Object variable not set

D

Danny

I am getting the error "Object variable or with block variable not set" when
the Form_Current event runs. Here's the first part of the code in
Form_Current:

Dim db As Database
Dim rstAlerts As Recordset
Dim i As Integer
Dim ExistingAddress As Recordset

If Nz(Me.strCustomerID, "") <> "" Then
Set ExistingAddress = db.OpenRecordset("SELECT
gtbl_People.strCustomerID, gtbl_People.strCompanyName,
gtbl_People.strSalutation, gtbl_People.strFirstName, gtbl_People.strMI,
gtbl_People.strLastName, gtbl_People.strSuffix, gtbl_People.strAddress2,
gtbl_People.strAddress, gtbl_People.strCounty, gtbl_People.strCity,
gtbl_People.strState, gtbl_People.strZip, gtbl_People.strPostalCode,
gtbl_People.strRegion, gtbl_People.strCountry, gtbl_People.Email,
gtbl_People.Phone, gtbl_People.strPlus4, gtbl_People.RenewalCode,
gtbl_People.ConversionCode, gtbl_People.Renew_Method FROM gtbl_People WHERE
strCustomerID = '" & Me.strCustomerID & "';")

When I select Debug I can verify that the Me.strCustomerID value is in
memory, and I can run a query that references that same value as a filter
criteria. So what else is going on here? Any ideas would be appreciated.

thanks.

Danny
 
D

Douglas J. Steele

You haven't instantiated the db object.

Set db = CurrentDb()

BTW, it would be advisable to change your definition to

Dim rstAlerts As DAO.Recordset
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top