Hi
I found some code that should do what I need, but can't figure out how to get it to work.
I need to copy a field entry "Request_Number" from an Access table "Activity_Requests" using excel vba and then store it as a string "OldRequestNo".
I want to use the automatic ID field in Access as a reference in determining which record I want info from. In this case, the highest ID.
Please help me adapt it
I don't want anything to be copied to any cells in excel, just to be stored as a variable.
Thanks!
I found some code that should do what I need, but can't figure out how to get it to work.
I need to copy a field entry "Request_Number" from an Access table "Activity_Requests" using excel vba and then store it as a string "OldRequestNo".
I want to use the automatic ID field in Access as a reference in determining which record I want info from. In this case, the highest ID.
Please help me adapt it
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sSQL As String
'// Use the Tools/References menu to add a reference to Microsoft DAO 3.xx Object Library
'// Change the filename/path as required
Set db = OpenDatabase("\\Work Request System.accdb")
'// Selecting all records where Field1 = Cell1 and Field2 = Cell2
sSQL = "Select * From Activity_Requests Where [XXXXX] = " & Range("C3").Value & _
" And [XXXXX] = " & Range("B3").Value
'// Get records
Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)
'// Anything found?
If Not rs.EOF Then
'// Paste recordset into worksheet - Change Cell address as needed
ActiveSheet.Range("A21").CopyFromRecordset rs
End If
'// Tidy up...
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
I don't want anything to be copied to any cells in excel, just to be stored as a variable.
Thanks!