Using an option group and a list box to preview a report

S

Sean

Hi, I am trying to bring up a report called "Job Details" when a person clicks on the first option from an option group (called ReportToPrint) and selects a job name from a list box (called selectJobName) and clicks on a the button called "preview" on the form called "Job Inquiries". Then the report should display the details fot the particular job they have selected from the list box. Here is the code for this button but the report is not displaying anything. Any ideas?

Private Sub preview_Click(
On Error GoTo Err_preview_Clic

Dim strWhereCategory As Strin

strWhereCategory = "JobName = Forms![Job Inquiries]!selectJobName

Select Case Me!ReportToPrin
Case
DoCmd.OpenReport "Job Details", acPreview, , strWhereCategor
Case
DoCmd.OpenReport "Job Details", acPrevie
End Selec

Exit_preview_Click
Exit Su

Err_preview_Click
MsgBox Err.Descriptio
Resume Exit_preview_Clic

End Sub
 
W

Wayne Morgan

strWhereCategory = "JobName = Forms![Job Inquiries]!selectJobName"

You are passing the form information inside the quotes, which simply causes
the text you have typed to be passed instead of the value of the control.
You need to concatenate the value into the string. Since the control is
called JobName, I'm guessing that it contains a string value. Adjust the
above line to:

strWhereCategory = "JobName = '" & Me!selectJobName & "'"

This will work if there aren't going to be apostrophes in the job name. If
there are, let me know and I'll adjust for that. Also, since the control is
on the form where the code is running and the value is now what it being
passed, it can be shortened as indicated.

--
Wayne Morgan
Microsoft Access MVP


Sean said:
Hi, I am trying to bring up a report called "Job Details" when a person
clicks on the first option from an option group (called ReportToPrint) and
selects a job name from a list box (called selectJobName) and clicks on a
the button called "preview" on the form called "Job Inquiries". Then the
report should display the details fot the particular job they have selected
from the list box. Here is the code for this button but the report is not
displaying anything. Any ideas??
Private Sub preview_Click()
On Error GoTo Err_preview_Click

Dim strWhereCategory As String

strWhereCategory = "JobName = Forms![Job Inquiries]!selectJobName"

Select Case Me!ReportToPrint
Case 1
DoCmd.OpenReport "Job Details", acPreview, , strWhereCategory
Case 2
DoCmd.OpenReport "Job Details", acPreview
End Select

Exit_preview_Click:
Exit Sub

Err_preview_Click:
MsgBox Err.Description
Resume Exit_preview_Click

End Sub
 
S

Sean

There will be apostrophes in the job name. I inserted the code that you gave me but the report is still coming u blank!
 
W

Wayne Morgan

Ok, if there will be apostrophes, then we need to send double quotes in the
string.

strWhereCategory = "JobName = """ & Me!selectJobName & """"

If option 2 is chosen, does the report open as expected?

--
Wayne Morgan
Microsoft Access MVP


Sean said:
There will be apostrophes in the job name. I inserted the code that you
gave me but the report is still coming u blank!
 
S

Sean

Yes if option 2 is chosen the report opens displaying all job name detail

----- Wayne Morgan wrote: ----

Ok, if there will be apostrophes, then we need to send double quotes in th
string

strWhereCategory = "JobName = """ & Me!selectJobName & """

If option 2 is chosen, does the report open as expected

--
Wayne Morga
Microsoft Access MV


Sean said:
There will be apostrophes in the job name. I inserted the code that yo
gave me but the report is still coming u blank
 

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