Open report that displays only certain records

human_anomaly

Registered User.
Local time
Today, 12:26
Joined
Apr 12, 2004
Messages
69
I am trying to open a report that only will show records that meets certain criteria. This is in a .adp database and I am having some trouble with it. I tried creating a macro and defining a where caluse of: [Student]=[Forms]![FrmSubStudent]![Student] and [Scenario]=[Forms]![FrmSubStudent]![Scenario] this isn't working though, when I click the button connected to the macro it gives me an error message "Invalid SQL statement check the server filter on the form record source" Does anyone have an idea to what I may be doing wrong?
 
h_a,

Forget the Macro. Make a command button your form with this line
of code:

Docmd.OpenReport "YourReport", , , "[Student] '" & Me.Student & "' and [Scenario] = '" & Me.Scenario & "'"

That's it.

The above assumes that the contents of [Student] and [Scenario] are strings.

Wayne
 
I guess I always had VBA as a backup plan I just never took the time to try it out. In any case it works great, just the way I wanted it. My final code ended up looking like this:

Private Sub Command17_Click()
DoCmd.OpenReport "RptFull", acViewPreview, , "[Student] = '" & Me.Student & "' and [Scenario] = '" & Me.Scenario & "' and [Date1] = '" & Me.Date1 & "' and [Teacher] = '" & Me.Teacher & "'"
DoCmd.RunCommand (acCmdZoom100)
DoCmd.Maximize
End Sub
 

Users who are viewing this thread

Back
Top Bottom