Joey said:
I have quite a large project created using DAO and since Access does not
automatically include a reference to DAO, if I distribute this, I know there
will be problems.
Is there a way to do late biding with DAO?? If so, what is the line of
code:
Set rs = CreateObject (????????)
Thanks for any suggestions.
If you create the database with a reference to the DAO library then this
reference should remain. It is only when you create a new database in A2K
onwards that the reference is missing. I have distributed many databases to
many machines and never had a problem when the reference is only to this
library, although I would use late binding for any MS Office automation code
I write.
For DAO, you might do better to write code to check your references rather
than remove them and use late binding. If you really insist, then don't
forget you will also have to define the constants such as dbOpenForwardOnly
when you open a recordset.
Private Sub TestDAO()
On Error GoTo Err_Handler
Dim dbs As Object
Dim rst As Object
Dim strSQL As String
Const dbOpenForwardOnly = 8
Set dbs = Application.CurrentDb
strSQL = "SELECT TOP 5 * FROM tblContacts"
Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardOnly)
While Not rst.EOF
MsgBox Nz(rst("ConFirst"), "")
rst.MoveNext
Wend
Exit_Handler:
On Error Resume Next
If Not dbs Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
Note: If the code is from Access you can start from Application.CurrentDb to
do most of things you need - as shown below.
If this is from vbs, where you can't use this, you have to start like:
Set eng = CreateObject("DAO.DBEngine.36")
Set dbs = eng.OpenDatabase("C:\Test\db1.mdb", True)