Button on form to print report for THAT record

kbrooks

Still learning
Local time
Today, 14:46
Joined
May 15, 2001
Messages
202
Hi, I have a database set up that we will use to record patient information when our normal system is down. I have a form set up where they enter all the information. I then have a report set up that will ask them for the patient account # (assigned on the form) and will print a sheet of labels for that patient.

I'd like to put a button on the bottom of the form that they can click to generate and print the "Labels" report. I tried setting one up, but it still asks for patient account #, since that's how I have my query set up that my report pulls from.

Is there any way to make it run the report for the current record that is open on the form? I'm sure there is but heck if I know how!
smile.gif


Thanks for any help you can give me!
 
You need to change the query that your report is based on, so that instead of asking for the patient account, it looks at the account field on the form. (The criteria would look something like this: [Forms]![fMyForm]![txtPatient_Acct])

Now, when you test that query and/or report, you'll need to have the form open. It can be minimized, tho, to get it out of your way.

[This message has been edited by Chris RR (edited 10-16-2001).]
 
Thanks, guys. Chris, I tried your suggestion and I got a compile error when I tried to open my form.

Pat, I'd like to try your suggestions but I need a little more help. I'm not sure what you mean by the OpenReport method or how to word a Where Clause. Also where to add the code you gave me for saving the report. I'm learning as I go and the code stuff really confuses me.

Thanks!
 
kbrooks the syntax looks something like this:

DoCmd.OpenReport "ReportName", acViewPreview, , _
"[FieldName] = '" & Criteria & "'"


Here is an example of that in code (cut and pasted from my app). There is a lot more going on here then just opening a report so if you need more explanation to what is going on inside the code just post back.

Dim strMsg As String, strTitle As String
Dim intStyle As Integer, cancel As Integer
Dim Answer As Variant
Dim strInput As String

strInput = InputBox("Enter job number", "Select Job")
If strInput = "" Then Exit Sub

If DCount("[JobNumber]", "TimeGR", "[JobNumber]= '" & strInput & "'") = 0 Then
strMsg = "Please try a different number"
strTitle = "Report Not Found"
intStyle = vbOKCancel + vbInformation
Answer = MsgBox(strMsg, intStyle, strTitle)
If Answer = vbCancel Then cancel = True
Exit Sub

End If

DoCmd.OpenReport "GRTimeSheet", acViewPreview, , _
"[JobNumber] = '" & strInput & "'"
 

Users who are viewing this thread

Back
Top Bottom