LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default update access mdb ...

this macro import a data from an access mdb all is ok!

My problem is:

if i change a record in variuos sheets of wbook is possible to updat
the relative record in the access mdb?

For example insert a button,associated a macro, on the sheet "Update t
Access"...


Code
-------------------
Sub EstrazioneDati()

' --- Esatto nome del Database completo del percorso
' --- nel caso il Database specificato non esista nel percorso, la macro genera un'errore
' --- verificare quindi l'esistenza del Database

Dim NomeDB As String

NomeDB = "\\srv04f9494rmtb\asp\TEMP\DBDELIVERY.MDB"

Dim StringaDiConnessione
StringaDiConnessione = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NomeDB & ";'"

Dim OggettoConnessione As Object, OggettoRecordsetUno, oggettoRecordsetDue As Object
Set OggettoConnessione = CreateObject("ADODB.Connection")
OggettoConnessione.Open StringaDiConnessione
Set OggettoRecordsetUno = CreateObject("ADODB.Recordset")
Set oggettoRecordsetDue = CreateObject("ADODB.Recordset")

' --- in questa istruzione SQL è possibile impostare condizioni di estrazione nell'argomento Where
' --- in questo caso vengono estratti solo gli Articoli con Qtà positiva

Set OggettoRecordsetUno = OggettoConnessione.Execute("SELECT * from TABELLA1 WHERE ID0")
Set oggettoRecordsetDue = OggettoConnessione.Execute("SELECT * from Tabella2 WHERE ID0")

Sheets("ANAGRAFICA").Select

Range("A4:N65536").ClearContents ' --- Pulisce la zona dove vengono estrapolati i dati del Database

Range("A4").Select ' --- Prima riga di Excel dove vengono incollati i dati

Do While Not OggettoRecordsetUno.EOF

' --- da notare che nelle istruzioni sotto Codice - Descrizione - Qtà corrispondono ai campi della Tabella articoli

ActiveCell = OggettoRecordsetUno("ID")
ActiveCell.Offset(0, 1) = OggettoRecordsetUno("DATA")
ActiveCell.Offset(0, 2) = OggettoRecordsetUno("DENOMINAZIONESOCIALE")
ActiveCell.Offset(0, 3) = OggettoRecordsetUno("SPORTELLO")
ActiveCell.Offset(0, 4) = OggettoRecordsetUno("NUMCONTRATTO")
ActiveCell.Offset(0, 5) = OggettoRecordsetUno("TIPOCONTRATTO")
ActiveCell.Offset(0, 6) = OggettoRecordsetUno("COGNOMEDESTINATARIO") & " " & OggettoRecordsetUno("NOMEDESTINATARIO")
ActiveCell.Offset(0, 7) = OggettoRecordsetUno("INDIRIZZO")
ActiveCell.Offset(0, 8) = OggettoRecordsetUno("CITTA")
ActiveCell.Offset(0, 9) = OggettoRecordsetUno("CAP")
ActiveCell.Offset(0, 10) = OggettoRecordsetUno("PROVINCIA")
ActiveCell.Offset(0, 11) = OggettoRecordsetUno("PREFISSO") & "/" & OggettoRecordsetUno("NUMEROTELEFONICO")
ActiveCell.Offset(0, 12) = OggettoRecordsetUno("NUMEROLETTORI")
ActiveCell.Offset(0, 13) = OggettoRecordsetUno("STATOLAVORAZIONE")
ActiveCell.Offset(1, 0).Select

OggettoRecordsetUno.Movenext

Loop

Range("A4").Select

Sheets("SMART_CARD").Select

Range("A4:H65536").ClearContents ' --- Pulisce la zona dove vengono estrapolati i dati del Database

Range("A4").Select ' --- Prima riga di Excel dove vengono incollati i dati

Do While Not oggettoRecordsetDue.EOF

' --- da notare che nelle istruzioni sotto Codice - Descrizione - Qtà corrispondono ai campi della Tabella articoli
ActiveCell = oggettoRecordsetDue("ID")
ActiveCell.Offset(0, 1) = oggettoRecordsetDue("DATA")
ActiveCell.Offset(0, 2) = oggettoRecordsetDue("COGNOMEFIRMATARIO") & " " & oggettoRecordsetDue("NOMEFIRMATARIO")
ActiveCell.Offset(0, 4) = oggettoRecordsetDue("DATANASCITA")
ActiveCell.Offset(0, 3) = oggettoRecordsetDue("CF")
ActiveCell.Offset(0, 5) = oggettoRecordsetDue("NUMSMARTCARD")
ActiveCell.Offset(0, 6) = oggettoRecordsetDue("NUMCONTRATTO")
ActiveCell.Offset(0, 7) = oggettoRecordsetDue("STATOLAVORAZIONE")
ActiveCell.Offset(1, 0).Select

oggettoRecordsetDue.Movenext

Loop

Range("A4").Select

MsgBox ("IMPORT TERMINATO!")

' --- chiusura degli oggetti

OggettoRecordsetUno.Close
oggettoRecordsetDue.Close
Set oggettoRecordsetDue = Nothing
Set OggettoRecordsetUno = Nothing
OggettoConnessione.Close
Set OggettoConnessione = Nothing

End Sub
--------------------



---
Message posted from http://www.ExcelForum.com/

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help How to update linked .xls offline with MS-ACCESS (VB)? Yaff Links and Linking in Excel 0 April 14th 07 02:40 PM
Excel update from Access Sharon A Excel Discussion (Misc queries) 0 June 14th 06 04:35 PM
Automatic Update from Access to EXcel Jay Excel Discussion (Misc queries) 0 February 11th 06 07:01 PM
export access to excel. change access & update excel at same time fastcar Excel Discussion (Misc queries) 0 June 24th 05 09:27 PM
update Access Table in Excel shin Excel Programming 2 January 24th 04 10:27 AM


All times are GMT +1. The time now is 04:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"