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:

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,452
Messages
5,511,468
Members
408,850
Latest member
NewUserPri

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