Update Query from Excel

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=487425
 
Last edited by a moderator:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Personally, I am not a big fan of trying to control Access with Excel, or vice versa.
Why not just create a User Form in Access where the user can update the data directly?

Also, be sure to provide links in your threads if you cross-post (I added them to your previous post).
 
Upvote 0
How do I start a connection with Access from Excel. I think I'll be able to get what I want when I know how to talk to Access at least.
 
Upvote 0
I found this also on this site. I think this is something that would help me out... I don't what DSN is though.

Code:
Dim MyConn As ADODB.Connection
Dim MyRS As ADODB.Recordset
Set MyConn = New ADODB.Connection
MyConn.Open "DSN=BARCLAYS"
 
MySQL = "Delete From Data Where Date >= '" & d & "'"
 
Set MyRS = MyConn.Execute(MySQL)
Set MyRS = Nothing
 
n = 2
Do Until Cells(n, 2) = ""
    MySQL = "Insert into Data Values (" & _
            "'" & Year(Cells(n, 2)) & "/" & Format(Month(Cells(n, 2)), "00") & "/" & Format(Day(Cells(n, 2)), "00") & "', " & _
            "'" & Cells(n, 3) & "', " & _
            "'" & Cells(n, 4) & "', " & _
            "'" & Cells(n, 5) & "', " & _
            "'" & Cells(n, 7) & "', " & _
            "'" & Cells(n, 8) & "', " & _
            "'" & Cells(n, 6) & "')"
    Set MyRS = MyConn.Execute(MySQL)
    Set MyRS = Nothing
    n = n + 1
Loop
 
MyConn.Close
 
Upvote 0
How do I start a connection with Access from Excel. I think I'll be able to get what I want when I know how to talk to Access at least.
Like I said, I don't really like controlling Access from Excel or vice versa, so I really don't ever do that.

However, if you search this forum, you should be able to find a lot of posts where people do that. It seems I see questions like that almost every day, so it shouldn't be too hard to find some.
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,942
Latest member
sharmarick

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
Back
Top