Link to home
Start Free TrialLog in
Avatar of michael1174
michael1174Flag for United States of America

asked on

Late binding DAO

I am using DAO and querydef... what would be the correct late binding?
I keep getting this erro:

ActiveX component can't create object

My code is below.. i think it is crashing on:

Set db = CurrentDb()

what would be the late binding for that?
Dim db As Database
Dim rs As Recordset
Dim qdf As QueryDef
 
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryRptWeeklyEmail")

Open in new window

Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Try this:


Dim db As Dao.Database
Dim rs As Dao.Recordset
Dim qdf As Dao.QueryDef
 
Try explicitly defining these as DAO, and make sure your references are set properly  (tools -> references, make sure DAO x.x is checked):

Dim db As DAO.Database
Dim rs As DAO.Recordset
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Be sure you have a reference set to DAO 3.xx in Tools>>References ....

mx
Avatar of michael1174

ASKER

I'm giving my client the mde and i dont want to have to specify the reference.....
Then angeliii's second suggestion should work for you.
Why not just:

Set qdf = CurrentDb.QueryDefs("qryRptWeeklyEmail")


  If this is an Access app (which it sounds like since you said your giving the client a MDE) then I would not use late binding.  There is a substantial performance hit in doing so.  Besides, there is not a ton that can go wrong with DAO as a reference.  It's considered part and parcel of Access (actually JET).

JimD
databaseMX, I'll try that as well...it works fine on my computer, but doesnt on my client's computer...
"but doesnt on my client's computer..."

Why not ? It should work on any computer.

mx
my client is still getting the error... maybe its the late binding on my outlook procedure....does it look right?
Private Sub EmailActivityReport(strClientName, strEmail)
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object
Dim arrEmail
Dim l_counter
Const olTo As Long = 1
Const olMailItem As Long = 0
 
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
 
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
 
 
With objOutlookMsg
    arrEmail = Split(strEmail, ",")
 
    For l_counter = 0 To UBound(arrEmail)
        Set objOutlookRecip = .Recipients.Add(arrEmail(l_counter))
        objOutlookRecip.Type = olTo
        Set objOutlookRecip = Nothing
    Next
 
 
   ' Set the Subject, Body, and Importance of the message.
   .Subject = "Invoice Activity Summary For " & strClientName
   .Importance = 2 'high importance
   .HTMLBody = strReport
   
 
   ' Resolve each Recipient's name.
   For Each objOutlookRecip In .Recipients
       objOutlookRecip.Resolve
   Next
 
   .Send
 
End With
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
End Sub

Open in new window

does anything look wrong here:
Public Sub CreateEmailActivityReport()
Dim rs As Object
Dim qdf As Object
Dim strEmail As String
Dim intClientID As Integer
Dim intLastClientID As Integer
Dim curTotalOriginalBalance As Currency
Dim curTotalRevisedBalance As Currency
Dim curTotalTotalCredits As Currency
 
Set qdf = CurrentDb.QueryDefs("qryRptWeeklyEmail")
 
qdf!pClientID = Forms!frmReports!cboClientID
qdf!pInvoiceFromDate = Forms!frmReports!txtInvoiceFromDate
qdf!pInvoiceToDate = Forms!frmReports!txtInvoiceToDate
qdf!pCarrierID = Forms!frmReports!cboCarrierID
qdf!pAuditorID = Forms!frmReports!cboAuditorID
 
 
Set rs = qdf.OpenRecordset
 
If rs.EOF Then
    MsgBox "Please assign email addresses to clients before running this report", vbInformation, strCompany
    Exit Sub
End If
 
.....

Open in new window

What line of code does that error occur on ?

mx
in my original post, it was occuring on the :

Set db = CurrentDb()

but once i changed
Dim db As Database

to

Dim db As Object

it was fine on my computer...

that was only way i could duplicate the error... nothing else has given me the error, so i'm not sure where it exactly is occuring on my clients computer...
Do you have a reference set to DAO for sure ? When you create a new MDB and go into code, the default reference (sadly) is ADO.

mx
I don't have a reference to DAO.. should I? if I am giving them an mde.. also, sorry, this is an access 2007 accde.

I've defined it as:


Dim rs As Object
Dim qdf As Object
 
Set qdf = CurrentDb.QueryDefs("qryRptWeeklyEmail")
 
Set rs = qdf.OpenRecordset

Open in new window

I believe OpenRecordset in Set rs = qdf.OpenRecordset is going to require a Reference to DAO.  Can you try that?

mx
ok, i try and add it and i get this error:

name conflicts with existing module, project, or library

i have checked:

visual basic for applications
microsoft access 12.0 object library
ole automation
microsoft office 12.0 access database engine object library
microsoft activex data objects 2.8 library
i just removed:

microsoft office 12.0 access database engine object library

and it allowed me to add it...

gonna see if it works at my clients cpu...
ok ... you're in A2007, right?

I guess microsoft office 12.0 access database engine object library is the DAO reference ... I'm not at my A2007 machine right now.

Typically that reference would look like:

Microsoft DAO 3.6 Object Library ....

mx
It actually had something to do with either the outlook automation call or the dao call, and my client didn't have the windows automatic update on, so my version of access 2007 was newer than his version.. the MSO numbers were different... once he downloaded microsoft updates, the code worked like a charm.