-
Did an example code for this to use in Excel. Need to refrence Microsoft DAO Object Ligbrary 3.?? - To do this, in the VB window select TOOLS - REFRENCES and tick it from the list
Function GetAccessValuesIntoExcel() As Boolean
'will return True if it works, false if it failed.
On Error GoTo Exit_GetAccessValuesIntoExcel
GetAccessValuesIntoExcel = False
Dim oJet As DAO.Workspace
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lRows As Long
'creat Jet workspace
Set oJet = CreateWorkspace("", "admin", "", dbUseJet)
'open jet db
Set db = oJet.OpenDatabase("C:\myDirectory\myDatabase.mdb")
'open recordset
Set rs = db.OpenRecordset("SELECT ID, myField FROM tblMyTable")
'print filed titles
Cells(1, 1).Value = rs.Fields(0).Name
Cells(1, 2).Value = rs.Fields(1).Name
lRows = 2
'print recordset values to the excel
While Not rs.EOF
Cells(lRows, 1).Value = rs("ID").Value
Cells(lRows, 2).Value = rs("MyField").Value
lRows = lRows + 1
rs.MoveNext
Wend
GetAccessValuesIntoExcel = True
Exit_GetAccessValuesIntoExcel:
'clean up
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
oJet.Close
Set oJet = Nothing
End Function
Dave
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules