Complie error: Variable not defined

Hello Experts:  

When I try opening my report I get this error:  Variable not defined on the 6th line at dbOpenSnapshot.  Also the first line is highlighted in yellow.  Here is the code example.

Private Sub Report_Open(Cancel As Integer)
Dim db As Database
Dim rs As Recordset
  Set db = CurrentDb
  Set rs = db.OpenRecordset("SELECT Min([Start Date]) AS MinOfStartDate " _
                & " FROM Projects", dbOpenSnapshot)
  If rs.RecordCount > 0 Then
    mdatEarliest = rs!MinOfStartDate
  End If
  Set rs = db.OpenRecordset("SELECT Max(IIf(IsDate([End Date]),CDate([End Date]),Null)) " _
                & "AS MaxOfEndDate FROM Projects", dbOpenSnapshot)
  If rs.RecordCount > 0 Then
    mdatLatest = rs!MaxOfEndDate
  End If
 
  mintDayDiff = DateDiff("d", mdatEarliest, mdatLatest)
 
  Me.txtMinStartDate.Caption = Format(mdatEarliest, "mm/dd/yyyy")
  Me.txtMaxEndDate.Caption = Format(mdatLatest, "mm/dd/yyyy")
  Set rs = Nothing
  Set db = Nothing
End Sub

Thanks.
SOUTHAMERICA70Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Have you checked your references to see if any are listed as missing?  Do you have a reference to DAO?
0
carazuulCommented:
Hi SOUTAMERICA70,
You may have trouble with mdatEarliest, mdatLatest, and mintDayDiff if you are using Option Explicit at the top of the code page. Also, if txtMinStartDate and txtMaxEndDate are text boxes as the naming implies you'll need to change the value instead of the caption.
Regards,
carazuul
0
SOUTHAMERICA70Author Commented:
matthewspatrick:

Thanks,
I added the DAO.  But now I get a runtime error:  Type mismatch on the 4th line Set db = CurrentDb
0
Patrick MatthewsCommented:
Change your declarations to:

Dim db As DAO.Database
Dim rs As DAO.Recordset
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SOUTHAMERICA70Author Commented:
matthewspatrick:

Thank you very much for your help.  That fixed my problem.  Many Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.