Hello All -
I am attempting to have my code run a series of UPDATE statments keyed off of a list of data in my Excel sheet that update my access database. I cannot figure out what is the best way to accomplish this as the excel data will change each time the code is run. below is a sample of the code i am working with that includes a few of the different angles i have attempted. Please let me know of course if there is any more information I can supply. Thanks.
Sub UpdateSomeRecordsADO()
Dim cnn As ADODB.Connection
Dim UpdCommand As ADODB.Command
Dim dbstrg As String
Dim UpdStrg As String
dbstrg = ""
dbstrg = dbstrg & "O:\AP\2008\testdb.mdb"
' dbstrg = dbstrg & Cells(2, 12)
' dbstrg = dbstrg & "\North American "
' dbstrg = dbstrg & Cells(2, 11)
' dbstrg = dbstrg & ".mdb"
'' Open the connection.
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Open dbstrg
'' Set the command text.
Set UpdCommand = New ADODB.Command
Set UpdCommand.ActiveConnection = cnn
'' - - - - - - - - - - - - - - - - - - - - - - - - - - - -
UpdStrg = ""
UpdStrg = UpdStrg & "UPDATE [Sheet1] SET [Paid] = 'Confirmed' WHERE [Acct] = 00003 AND [T/D] = 20080512 AND [B/S] = 1 AND [Price] = 1388.25"
' vtSql = vtSql & " UPDATE " & "Sheet1"
' vtSql = vtSql & " SET Salaryx= 24680"
' vtSql = vtSql & " WHERE Namex='Jennings'"
With UpdCommand
.CommandText = UpdStrg
.CommandType = adCmdText
.Execute
End With
' Loop
'Range("Q2").Select
' Do
' UpdCommand.Execute
' ActiveCell.Offset(1, 0).Select
' Loop Until IsEmpty(ActiveCell.Offset(0, -16))
'' Close the connections and clean up.
cnn.Close
Set UpdCommand = Nothing
Set cnn = Nothing
End Sub
I am attempting to have my code run a series of UPDATE statments keyed off of a list of data in my Excel sheet that update my access database. I cannot figure out what is the best way to accomplish this as the excel data will change each time the code is run. below is a sample of the code i am working with that includes a few of the different angles i have attempted. Please let me know of course if there is any more information I can supply. Thanks.
Sub UpdateSomeRecordsADO()
Dim cnn As ADODB.Connection
Dim UpdCommand As ADODB.Command
Dim dbstrg As String
Dim UpdStrg As String
dbstrg = ""
dbstrg = dbstrg & "O:\AP\2008\testdb.mdb"
' dbstrg = dbstrg & Cells(2, 12)
' dbstrg = dbstrg & "\North American "
' dbstrg = dbstrg & Cells(2, 11)
' dbstrg = dbstrg & ".mdb"
'' Open the connection.
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Open dbstrg
'' Set the command text.
Set UpdCommand = New ADODB.Command
Set UpdCommand.ActiveConnection = cnn
'' - - - - - - - - - - - - - - - - - - - - - - - - - - - -
UpdStrg = ""
UpdStrg = UpdStrg & "UPDATE [Sheet1] SET [Paid] = 'Confirmed' WHERE [Acct] = 00003 AND [T/D] = 20080512 AND [B/S] = 1 AND [Price] = 1388.25"
' vtSql = vtSql & " UPDATE " & "Sheet1"
' vtSql = vtSql & " SET Salaryx= 24680"
' vtSql = vtSql & " WHERE Namex='Jennings'"
With UpdCommand
.CommandText = UpdStrg
.CommandType = adCmdText
.Execute
End With
' Loop
'Range("Q2").Select
' Do
' UpdCommand.Execute
' ActiveCell.Offset(1, 0).Select
' Loop Until IsEmpty(ActiveCell.Offset(0, -16))
'' Close the connections and clean up.
cnn.Close
Set UpdCommand = Nothing
Set cnn = Nothing
End Sub