Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Complie error:  Variable not defined

Posted on 2008-11-11
5
Medium Priority
?
280 Views
Last Modified: 2013-11-27
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.
0
Comment
Question by:SOUTHAMERICA70
  • 2
  • 2
5 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 22932024
Have you checked your references to see if any are listed as missing?  Do you have a reference to DAO?
0
 
LVL 6

Expert Comment

by:carazuul
ID: 22932102
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
 

Author Comment

by:SOUTHAMERICA70
ID: 22932392
matthewspatrick:

Thanks,
I added the DAO.  But now I get a runtime error:  Type mismatch on the 4th line Set db = CurrentDb
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 22932407
Change your declarations to:

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

Author Comment

by:SOUTHAMERICA70
ID: 22932533
matthewspatrick:

Thank you very much for your help.  That fixed my problem.  Many Thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question