Update query to Access VB

wbtrimble

New Member
Joined
Aug 10, 2010
Messages
6
I created a query in Access and exported it to a file so my co-worker can update and changes. I need now to be able to create an Update Query from Excel to Access to update the data in the query. However I'm not really sure on how to go about doing it. I took the following code and changed to fit my datbase but I don't see an update area in there. Am I on the right track or way off??

Any help would be greatly appreciated.

I have the following code:

Code:
Dim cn As Object, rs As Object, Status As Range
Dim MySql As String, dbfullname As String, myCnt As Long
dbfullname = "P:\Databases\Access Database Development\6.TestDatabases\testtable.mdb"
Set Status = Sheets("testquery").Range("A2") 'SQL Variable
MySql = "SELECT ProjectID,ProjectInfo.OppId,Po_Value,ProjectInfo.Submitter,Comments, " _
& "OppTable.OppId,Customer,Plant,OppTable_Submitter " _
    & "FROM testquery WHERE " & _
    "projectid ='" & Status & "';" 'Stack your SQL string
Status = Empty 'Clear SQL variable string
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " _
       & dbfullname & ";"  'Create DB connection
 
Set rs = CreateObject("ADODB.Recordset")
With rs
    Set .ActiveConnection = cn
    .Source = MySql 'Pass your SQL
   .Open , , 3, 3
 
    myCnt = .RecordCount
 
    .Close
End With
cn.Close
Set rs = Nothing: Set cn = Nothing
End Sub

I'm not sure about the variable Status. This isn't exactly what I want... but the fields would look up the query with the Column A.

Cross-Post: http://www.mrexcel.com/forum/showthread.php?t=487426
 
Last edited by a moderator:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Watch MrExcel Video

Forum statistics

Threads
1,132,678
Messages
5,654,709
Members
418,149
Latest member
tjanok

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top