Open a report based on form fields

I

Iram

Hello.

I have 6 unbound combobox fields on a form and based on those fields I need
a button on the form to open one of three reports based upon the two fields.

One of the fields is the "Marital Status": Married, Divorced, Widowed, Youth.
The other field is "Sex": Male, Female.

If Married is selected for "Marital Status" then I need a report called
"rpt_ReportCasados" to open.

If Youth is selected I need one of two reports to open depending on the
"Sex". If Male then I need a report to open called "rpt_ReportJovenes". If
Youth is selected and if Female is selected as the Sex then I would need the
report called "rpt_ReportSenoritas".

Can you please help with this?

Thanks.
Iram/mcp
 
M

Mr. B

Iram,

My suggestion would be to use a Select Case statement to determine the
selection made from the "Marital Status" combo box and then use an If
statement within each Case to determine the appropriate report to be run.
Something like:

Select Case Me.NameOfMaritialStatusCombobox

Case "Married"
If Me.NameOfSexComboBox = "Male" then
docmd.openReport "ReportName"
Else
docmd.openReport "ReportName"
endif

Case "Divorced"
If ...

Else

end if

'additional case statements here

End Select

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
 
I

Iram

Thanks Mr. B.

There is only one problem. When I click the button it prints the report
instead of letting me preview it. Can you help me modify the code to fix
this. I had to change a little bit of your code since I wasn't sure how the
database was designed...

Private Sub ReporteDeCasados_Click()
Select Case Me.Edo_Civil

Case "1"
If Me.Sexo = "Masculino" Then
DoCmd.OpenReport "rpt_ReportJovenes"
Else
DoCmd.OpenReport "rpt_ReportSenoritas"
End If

Case "2"
DoCmd.OpenReport "rpt_ReportCasados"

'additional case statements here

End Select


End Sub

:



Thanks.
Iram/mcp
 
G

Graham Mandeno

Hi Iram

Add acViewPreview as the second argument to your OpenReport method:

DoCmd.OpenReport "rpt_ReportJovenes", acViewPreview
 
G

Gina Whipp

Iram,

Here you go...

Private Sub ReporteDeCasados_Click()
Select Case Me.Edo_Civil

Case "1"
If Me.Sexo = "Masculino" Then
DoCmd.OpenReport "rpt_ReportJovenes", acViewPreview
Else
DoCmd.OpenReport "rpt_ReportSenoritas", acViewPreview
End If

Case "2"
DoCmd.OpenReport "rpt_ReportCasados", acViewPreview

'additional case statements here

End Select


End Sub


--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 

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