variable not defined error

S

Steve

Hi,
I copied the code from a switchboard button the works, but get a "compile
error, variable not defined" error message for this one. I highlights the
"stCriterion = statement.
Any help would be gratefully accepted.

Thanks,

Private Sub cmdMissedReq_Click()
On Error GoTo Err_cmdMissedReq_Click

Dim stDocName As String
Dim stStartDate As Date
Dim stEndDate As Date

stCriterion = ""

If IsNull(Forms!frmRptsbyDate!StartDate) Then
MsgBox "No Start Date, using All Dates"
GoTo Print_Report
End If
stStartDate = Forms!frmRptsbyDate!StartDate
If IsNull(Forms!frmRptsbyDate!EndDate) Then
MsgBox "No End Date, using All Dates"
GoTo Print_Report
End If

stEndDate = Forms!frmRptsbyDate!EndDate
stCriterion = "(RequestDate between #" & stStartDate & "# AND #" &
stEndDate & "#)"


stDocName = "rptMissedRequests"
DoCmd.OpenReport stDocName, acPreview, , stCriterion
Print_Report:

stDocName = "rptMissedRequests"
DoCmd.OpenReport stDocName, acPreview, , stCriterion

Exit_cmdMissedReq_Click:
Exit Sub

Err_cmdMissedReq_Click:
MsgBox Err.Description
Resume Exit_cmdMissedReq_Click

End Sub
 
S

Stuart McCall

Steve said:
Hi,
I copied the code from a switchboard button the works, but get a "compile
error, variable not defined" error message for this one. I highlights the
"stCriterion = statement.
Any help would be gratefully accepted.

Thanks,

Private Sub cmdMissedReq_Click()
On Error GoTo Err_cmdMissedReq_Click

Dim stDocName As String
Dim stStartDate As Date
Dim stEndDate As Date

stCriterion = ""

If IsNull(Forms!frmRptsbyDate!StartDate) Then
MsgBox "No Start Date, using All Dates"
GoTo Print_Report
End If
stStartDate = Forms!frmRptsbyDate!StartDate
If IsNull(Forms!frmRptsbyDate!EndDate) Then
MsgBox "No End Date, using All Dates"
GoTo Print_Report
End If

stEndDate = Forms!frmRptsbyDate!EndDate
stCriterion = "(RequestDate between #" & stStartDate & "# AND #" &
stEndDate & "#)"


stDocName = "rptMissedRequests"
DoCmd.OpenReport stDocName, acPreview, , stCriterion
Print_Report:

stDocName = "rptMissedRequests"
DoCmd.OpenReport stDocName, acPreview, , stCriterion

Exit_cmdMissedReq_Click:
Exit Sub

Err_cmdMissedReq_Click:
MsgBox Err.Description
Resume Exit_cmdMissedReq_Click

End Sub

"variable not defined" means that you need to declare the variable, just
like the other three variables are declared at the start of the procedure.
Add this line immediately under the existing declarations:

Dim stCriterion As String
 
J

Jeff Boyce

Steve

Take a look at the three "Dim" statements in your function. You don't see
one for "stCriterion" do you?

If you are going to use a variable, it's just good programming practice to
'Dim' it first.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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