Report for Current Record on form without Prompting for ID

chapmajm

Registered User.
Local time
Today, 03:52
Joined
Mar 22, 2007
Messages
28
I've been trying to figure this out for hours now. I need the code to Preview a report for only the current record on my form without prompting for the ID.

I'm making a patient report database.

This is the code I'm using now... is there a way I could simply revise this code so I won't have to enter the PatientID every time I want to preview the Consult report? Please help... people are counting on me.

BTW... it took me forever to figure the code below out. I'm no expert.

Private Sub Command70_Click()
On Error GoTo Err_Command70_Click

Dim stDocName As String

stDocName = "Consult"
DoCmd.OpenReport stDocName, acPreview, , "[PatientID]=[Forms]![PatientInfo]![PatientID]"

Exit_Command70_Click:
Exit Sub

Err_Command70_Click:
MsgBox Err.Description
Resume Exit_Command70_Click

End Sub
 
I've compared your code to a working example in one of my databases and I can't see anything wrong. I don't mean to patronise but I take it the id number is a field on your report?

Otherwise, as a test you could paste this working code into your event

DoCmd.OpenReport "Consult", acPreview, "", "[PatientID]=[Forms]![PatientInfo]![PatientID]"

Also you might want to look at using a naming convention to help distinguish what is what ie 'rptConsult' 'frmPatientInfo" etc
 
Is PatientID text or numeric?
 
It's numeric, but no, I don't patient ID on my report. Is that what I need to do? If so, could that field be hidden? Thanks for replying. I'm going to try your code... Thanks :)
 
Yes, it would need to be in the report's recordset.
 
Both codes work fine, if I want the command button to prompt me to enter the PatientId... I see the patient that is assigned to that ID on the report. What I'm trying to do is click the command button and it grabs the PatientID that's on the current form, without me having to type the PatientID.
 
It is in the report's field list, but I chose not to put it on the report. I actually just tried adding it to the report but it still didn't work. The command button still prompted for patientid.
 
Then you aren't referring to it properly. Are you sure that it is [PatientID] and not [Patient ID] with a space or something?
 
It used to be Patiend ID, but I changed the field name in the table and on the report. OH! I just noticed that on the report field list, it's still Patient ID. Is that why?
 
You are brilliant! It worked! Thanks so much!!!!!!!!!!!!!!!!!!!!!!! It was because previously I had named the field Patient ID, then renamed it PatientID to make the coding easier. Wow. Thank you!!!!
 
Glad to hear it's working for you. It sure feels nice, doesn't it, to get something working that was causing so much pain. :D
 

Users who are viewing this thread

Back
Top Bottom