Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a report from a form.

Status
Not open for further replies.

aaabuhalime

Instructor
Nov 22, 2012
67
US
Hi ,
I just started anew job, I am dealing with a database that been created by different people, I have a difficulty in opening one of the reports,I have a report called(glowEligibiltyRpt)generated from a query called(QryEigibilty_Post)and a form as well called Eligibility, The query, report the form work as expected. the form and the report are generated from that query,I have a button on the form to open the report, when I open the report a box pops up asking me to enter a parameter value, Enter the Participant ID and the Assessment date, What I want to do is have a command button on a Form that when click occurs the report will open with the records matching the participant Id and Assessment date on the form.
I opens the query I deleted the criteria to stop asking for the parameters, what ever criteria I include in their the parameter box appear again asking for the values, so I need help , again what I need is when Enter the participant ID and the visit date, and click on the button I want open the report with matching records.

Any help will be appreciated,
 
Hi,
I tried to generate the same problem with a small db at home, I have tried the following code under the command button
Private Sub Command10_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "Report4"
stWhere = "[SID] = """ & Me.[SID] & """ And [SData]=#" & Me.SDate & "#"
DoCmd.OpenReport strDocName, acPreview, , strWhere
End Sub

The report open with no problems but it generates all records, even if I enter the ID or date still displays all records how can I just limit the report to only display the record for the specified data, I am sorry to bother again, any help will be appreciated.
Note: the report and the form created from the same query.
 
I am not seeing the option Explicit in the declarations section, I think the code compiles fine, I did not receive any compiler error, I can share the screen with you if possible.
 
I pointed out the error with your variable names not matching. Type
Option Explicit
At the very top of each code window and then compile all code after you make changes

Duane
Hook'D on Access
MS Access MVP
 
Hi and thank you very much for your help,I have another question please,I have a form created from a query, the form displays Information about Teachers, Principles and Students, I have a combobox that holds the values (Teachers, Students, Principles), When the Teacher is selected from the combo box all the teachers related info displayed and , the Not realted teacher information, or tha fields that doeasnt apply to the teacher remains blank, same thing applies to students and principles case, my question is their a way to get those filds greyed out, for example when I select/enter the teacher info all the non applicable (fields blank) get greyed out, and when I select/enter students info all the blank fields that don't apply to students get greyed out and so on .......Any help on how to do that will appreciated.

Thanks
 
Dear dhookm,
I have the follwing code, it wroked fine, I was using Access 2010, I changed to 2007, bcz 2010 gave a lot of unxpected errors, I end up losing the code,unexpectedly, now I am using the same code that worked before, I can open the report, but it dispalys an emapty report, whatever ID , assessment date I enter on the form, the report comes back empty, any help please?

Private Sub Command108_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "rpt_Preg"
stWhere = "[ParticipantID]= """ & Me.[ParticipantID] & """ And [SDate]=#" & Me.SDate & "#"
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub
 
You have to choose: strWhere or stWhere ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ok, I tried the following code but still it shows all records. what do you think?

Private Sub Command108_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "rpt_Preg"
strWhere = "[ParticipantID]= """ & Me.[ParticipantID] & """ And [SDate]=#" & Me.SDate & "#"
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub
 


ok, I tried the following two codes but the first code still it shows all records. while the second doesn't show any records ..any thoughts??

Private Sub Command108_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "rpt_Preg"
strWhere = "[ParticipantID]= """ & Me.[ParticipantID] & """ And [SDate]=#" & Me.SDate & "#"
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub

Second Code:


Private Sub Command108_Click()
Dim strDocName As String
Dim stWhere As String
strDocName = "rpt_Preg"
strWhere = "[ParticipantID]= " & Me.[ParticipantID] & " And [SDate]=#" & Me.SDate & "#"
DoCmd.OpenReport strDocName, acPreview, , stWhere

End Sub


any help will be appreciated.

Thanks
 
For about the 4th or 5th time change:
Code:
   strWhere = "[ParticipantID]= " & Me.[ParticipantID] & " And [SDate]=#" & Me.SDate & "#"
   DoCmd.OpenReport strDocName, acPreview, , [COLOR=#204A87][b][i]stWhere[/i][/b][/color]

Code:
   strWhere = "[ParticipantID]= " & Me.[ParticipantID] & " And [SDate]=#" & Me.SDate & "#"
   DoCmd.OpenReport strDocName, acPreview, , [COLOR=#204A87][b][i]strWhere[/i][/b][/color]

I don't know why your first code doesn't work. I would add a breakpoint to make sure the code is being run.

You have also been told to add Option Explicit to your code and then compile. I'm not sure why you don't do this.

Duane
Hook'D on Access
MS Access MVP
 
Yes, the code worked fine , I did all of that and worked fine. all is perfect now.

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top