Open a report based on form fields

  • Thread starter Thread starter Iram
  • Start date Start date
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
 
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
 
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
 
Hi Iram

Add acViewPreview as the second argument to your OpenReport method:

DoCmd.OpenReport "rpt_ReportJovenes", acViewPreview
 
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
 
Back
Top