Using Parameters in a Form

P

Paul

Hi All,
I built a form called Reports and I want to add a Option
button or Label once it clciks it will prompt the user for
a Start Date and End Date:
My current code for my form is below. I havie been using
the NorthWInd Datbase as my guide. Any suggestions?

Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_Preview_Click
' This procedure used in Preview_Click and Print_Click
Sub procedures.
' Preview or print report selected in the
ReportToPrint option group.
' Then close the Reports form.

Dim strWhereCategory As String

strWhereCategory = "CategoryName = Forms![Reports]!
SelectCategory"

Select Case Me!ReportToPrint
Case 1
DoCmd.OpenReport "Report1", PrintMode
Case 2
DoCmd.OpenReport "Report2", PrintMode
Case 3
If IsNull(Forms![Reports]!SelectCategory) Then
DoCmd.OpenReport "Report3", PrintMode
Else
DoCmd.OpenReport "Report3", PrintMode, ,
strWhereCategory
End If
End Select
DoCmd.Close acForm, "Reports"

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
Resume Exit_Preview_Click

End Sub
 
L

Larry Linson

You're almost there... your strWhereCategory should be

strWhereCategory = "CategoryName = """ & Forms![frmReports]!SelectCategory
& """"

Now, note that I changed the name of the form... it is not a good idea at
all to use an Access keyword as the name of an object -- sooner or later it
will be confusing. ("Reports" is the name of the Collection of open Reports
in Access.)

Larry Linson
 
P

Paul

Hey Larry,
SO how do I put a label on the form to activate paremters?
Can I emai lyou my DB?
-----Original Message-----
You're almost there... your strWhereCategory should be

strWhereCategory = "CategoryName = """ & Forms! [frmReports]!SelectCategory
& """"

Now, note that I changed the name of the form... it is not a good idea at
all to use an Access keyword as the name of an object -- sooner or later it
will be confusing. ("Reports" is the name of the Collection of open Reports
in Access.)

Larry Linson

Hi All,
I built a form called Reports and I want to add a Option
button or Label once it clciks it will prompt the user for
a Start Date and End Date:
My current code for my form is below. I havie been using
the NorthWInd Datbase as my guide. Any suggestions?

Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_Preview_Click
' This procedure used in Preview_Click and Print_Click
Sub procedures.
' Preview or print report selected in the
ReportToPrint option group.
' Then close the Reports form.

Dim strWhereCategory As String

strWhereCategory = "CategoryName = Forms![Reports]!
SelectCategory"

Select Case Me!ReportToPrint
Case 1
DoCmd.OpenReport "Report1", PrintMode
Case 2
DoCmd.OpenReport "Report2", PrintMode
Case 3
If IsNull(Forms![Reports]!SelectCategory) Then
DoCmd.OpenReport "Report3", PrintMode
Else
DoCmd.OpenReport "Report3", PrintMode, ,
strWhereCategory
End If
End Select
DoCmd.Close acForm, "Reports"

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
Resume Exit_Preview_Click

End Sub


.
 

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