Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help How to update linked .xls offline with MS-ACCESS (VB)? | Links and Linking in Excel | |||
Excel update from Access | Excel Discussion (Misc queries) | |||
Automatic Update from Access to EXcel | Excel Discussion (Misc queries) | |||
export access to excel. change access & update excel at same time | Excel Discussion (Misc queries) | |||
update Access Table in Excel | Excel Programming |