To open a report with a query

JRPMD

Registered User.
Local time
Yesterday, 17:46
Joined
Nov 24, 2012
Messages
52
Hello ,I need some help with a Report.
It is based on a query with this criteria in the field document number:
[Forms]![Administrativos3]![Pacientes_Nro de documento]
I have a Form with this fields : Pacientes_Nro de documento , edad , sexo , HTA.
And many reports named Laboratorio .
I try to open the reports with this module :

Private Sub Etiqueta42_Click()
If (Me.Edad >= 50) And (Me.Sexo = "Masculino") And (Me.HTA = 1) = True Then DoCmd.OpenReport "Laboratorio", acViewPreview
If (Me.Edad >= 50) And (Me.Sexo = "Masculino") And (Me.HTA = 2) = True Then DoCmd.OpenReport "Laboratorio2", acViewPreview
If (Me.Sexo = "Femenino") And (Me.HTA = 1) = True Then DoCmd.OpenReport " Laboratorio3", acViewPreview
If (Me.Sexo = "Femenino") And (Me.HTA = 2) = True Then DoCmd.OpenReport "Laboratorio4", acViewPreview
End Sub
The Reports opens properly , i.e. report "Laboratorio" opens if the actual record in the form is >50 ,male and HTA=1 .
But the querys does't work because this same fields are empty in the report.
There is one query for each report and it works if I open the report directly from its icon , but not if I try using the module.
Should I made another module to make de query works?
Is there something bad in the design of this DB?
Thank you very much.
 
Checking to see if when you open the report directly, you get the correct results, but when you open from the form, you do not? Are the criteria in the query the same as what is selected from the form? If not, then you would need to include the criteria in the open report code. Also, are the queries and reports identical except for the criteria? If so, you could have one query and one report and then the code would handle filtering the data and changing the titles/labels on the report. Depending on your response, I can give some examples.
 
Thank you very much for your answer.
when I open the report directly I'm asked for a value to the field that is in the criteria of the query and it works well.
If the report is open from the form ,it is supossed that that the query looks for the value in the same field of the torm ; but it don't happens that way and the report opens with all empty fields , although the "If conditions" are satisfied and opens the correspondig report.
I tried this code from an another label in the same form:
Private Sub Label70_Click()
DoCmd.OpenReport "Laboratorio", acViewPreview
End Sub



and the behavior is the same , it opens an empty report.
Maybe you are right and I have to include the criteria in the open report code.
But , why a report that is based in a query with this criteria doesn't work when it is open from a code?
The conditions for the other fields in the second part of the code determines which report is open , so their values are recongnized.
The querys and identical. The reports are different only in lables and titles.
Can I have only one query? It would be great!

 
Hello sxschech , thanks again for your interest.
I think I made a mistake.
I create a new DB with a similar structure and code and the reports opens both from the form and directly.
Maybe there is something corrupt in the former DB.
Sorry for this confusing situation.
I'm still interested in making only one query and report
Thank you very much.
 

Users who are viewing this thread

Back
Top Bottom