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:

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,092
Office Version
365
Platform
Windows
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).
 

wbtrimble

New Member
Joined
Aug 10, 2010
Messages
6
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.
 

wbtrimble

New Member
Joined
Aug 10, 2010
Messages
6
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,092
Office Version
365
Platform
Windows
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.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,994
Messages
5,508,622
Members
408,689
Latest member
SamSan78

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top