Open Report with button

BartK

Registered User.
Local time
Today, 08:03
Joined
Jun 7, 2013
Messages
115
Hello everyone,
I'm probably missing something really simple here. I have a report that is a summary of multiple records in it. What I have next to the record on the report is a button.

I have report that are labeled:
rptIncident Summary
rptIncident Report
and a button labeled
"open report"

I would like to click on the button and then it open the rptIncident Report with all the information, not just the summary. I will put a picture so you know what I am trying to accomplish.

Is this a simple Onclick event with a where condition or what? Or does this go beyond to having something to do with VBA? Thanks all.
 

Attachments

  • Capture.JPG
    Capture.JPG
    22.6 KB · Views: 113
What do I put in the where condition of the macro. It looks like what you have listed there is for VBA. Thanks
PBaldy,
I've tried putting the vba code you suggested. What is the control name? Is that the table the records are stored in?? Thanks once gaain.
 
Last edited:
I did notice an unexpected action with the following code:

Private Sub Command29_Click()
DoCmd.OpenReport "Incident Report", , , "Date = #" & Me.Date & "#"
End Sub

It prints out the record in the table, Kind of interesting. I will have to remember it for later.
 
If you look in help at OpenReport, you're missing the acPreview argument (printing is the default if unspecified).
 
The acPreview argument? Is that some type of setting in the report itself, in the code? I'm really lost now. As you can probably tell I'm very new to VBA. Thanks for the patience.
 
I take it you didn't look in help? Try

DoCmd.OpenReport "Incident Report", acViewPreview, , "Date = #" & Me.Date & "#"
 
I think I found out what I was looking for. You definatly pointed me on the right path, acViewReport is what I was shooting for. Thanks for your help once again.
 
I was able to get my report to pull whenever I used:
DoCmd.OpenReport "Incident Report", acViewReport, , "Date = #" & Me.Date & "#"

However whenever I have multiple records stored on the same date it pulls all of them at once, which is exaclty what the code is telling it to do. What I'm wanting to do is just to pull the one record. so I have tried this:
DoCmd.OpenReport "Report1", acViewReport, , "Citation # = '" & Me.Citation# & "'"

But I'm getting a compile error on Citation# Method or Data Member not found. There is a space between citation and # within my table. do I have to put [] around Citation # for it to work? Thanks once again.
 
What you used don't look like what Paul has showed you.

More:
Is the Citation a field that store dates ?
The "#" sign is used in order to tell SQL interpreter that should work with dates.
For other types of data the "#" sign is not used.
So:
If the Citation is a field that store dates then you should have:
DoCmd.OpenReport "Incident Report", acViewReport, , "Citation = #" & Me.Citation & "#"

else you should have:
DoCmd.OpenReport "Report1", acViewReport, , "Citation = '" & Me.Citation & "'"
 
Mihail,
To answer your question first, no the Citation # does not store dates it is purely a number. Also I've tried both of your suggestions and it still gives me the error Method or Data Member not found. Still highlights the Me.Citation Thanks for your help. Any other ideas?
 
Unless you misspelled something, this
DoCmd.OpenReport "Report1", acViewReport, , "Citation = '" & Me.Citation & "'"
should work

or, because the Citation is a numeric field, this
DoCmd.OpenReport "Report1", acViewReport, , "Citation = " & Me.Citation
should work as well

Blue = Field name in the Report's Record Source
Red = Control name in the form
 
Because of the inadvisable symbol (and space?) the field name needs to be bracketed.
 
Pballdy,
I went ahead with your advice and removed the space along with the # symbol. Still having issues. I am attaching what Access spits back to me. Had no idea it would become this complicated. It is highlighting the Me.Citation towards the end of the code.

Sorry for being such a noob.
 

Attachments

  • Capture.JPG
    Capture.JPG
    31.1 KB · Views: 95
Most likely is that control doesn't exist on the form. Double check the spelling.
 
Name on the form was something that wasn't matching. Got a new error now, I don't know if it's a good or a bad thing.

inherited this from someone who worked here a while back so I am learning as I go along, thank you for all the patience.
 

Attachments

  • Capture.JPG
    Capture.JPG
    36.4 KB · Views: 90
Can you post the db here?
 
Had to put it on a diet but I was able to attach it. I'm sure that you will be able to get it up and running, however I had to delete several other reports and tables to get it to where it is now. Forgot to say click on the "Citations By Area" on the switchboard. Input a range of dates and then on the report that comes up the button off to the far right is the button in which I"m having trouble with. Sorry

thank you so much for helping me, I know that there is no way I could of done it. You rock
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom