Hi everyone,
I am back using MS Access after 5+ years away from it (well, I did use it at home for some hobby related things). I used to use mainly A2003 (and 97 and 2), some A2007. I'm now in a position using A2016. Is DAO something that is now discouraged? I know that it is no longer a separate reference like 3.51 and 3.6 and seems to be included in the Microsoft Access 16.0 Object library or the Microsoft 16.0 Access database engine Object library.
Here's a simple, basic sub that runs through the results of a temporary querydef the way I would normally write it. The Jet/Ace SQL has no where clause, I'm just testing this method. Is there a better way to enumerate/row process a recordset or is this approach still acceptable?
Edit - terribly sorry, but the forum doesn't seem to accept my indents.
------ Start Code ------
Option Compare Database
Option Explicit
Public Sub sTest()
On Error GoTo Err_Proc
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As Recordset
Set db = Access.CurrentDb
Set qdf = db.CreateQueryDef("", "select * from tblTest")
With qdf
Set rs = .OpenRecordset(dbOpenSnapshot)
With rs
If .EOF Or .BOF Then
MsgBox "No records!", vbExclamation
Else
.MoveFirst
Do While .EOF = False
MsgBox .Fields!TestEntity
.MoveNext
Loop
End If
.Close
End With
.Close
End With
Exit_Proc:
On Error Resume Next
rs.Close
qdf.Close
db.Close
On Error GoTo 0
Set qdf = Nothing
Set db = Nothing
Exit Sub
Err_Proc:
Select Case Err.Number
Case Else
MsgBox "Access Error " & Err.Number & " " & Err.Description, vbCritical, "Error", Err.HelpFile, Err.HelpContext
Resume Exit_Proc
End Select
End Sub
------ End Code ------
Thank you in advance,
--
Tim