current record

Need help with Access also

I have followed everything, but I am getting all the records, I have now spent 6 hours on this its driving me mad, please can anyone help me, my event procedure listed blow.

Dim strDocName As String
Dim strWhere As String
strDocName = "Wilton 3 shot figured specification"
strWhere = "[ID]=Forms![Wilton 3 Shot Figured]![ID]"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport strDocName, acPreview, , strWher
 
Try this:

strWhere = "[ID]= " & Forms![Wilton 3 Shot Figured]![ID]

The difference is that in my example, the value for the argument is evaluated before the where argument is sent to the report. So if you were to stop the code and hover over the strWhere variable, you would see something like:

"[ID] = 483" -- with 483 being the ID of the current record.
 
Its worked!!! thanks Pat I had given up!!
 
Hi All,

Not sure if this post is still any interest. I wanted to thank all previous posters for their help. It allowed me get a code working, however I am experiencing one problem I am hoping someone can help with.

The code works for any field (text or numerical) in my form except for the ID autonumber field. And the crunch is that the ID field is the only unique field in my table. When I use the code with ID entered as the field name I get a pop-up requesting user "Enter Parameter Value". If I switch the field name to any other field on the form, this message does not pop-up and the current record is selected and printed accordingly. I have also tried switching the autonumber field name to "Entry" and the same window pops-up.

Any ideas on where I could correct this would be greatly appreciated. Thanks in advance.
 
Sounds like you are invoking the Parameter function when using [square brackets]. Check all the references to the fields are correct.
 
I have tried everything in this thread to get a report to print only the current record. However, each time I try to print I am getting a prompt for the unique ID just like a previous user. I have tried to find any typos but everything looks correct. This is my code:

Private Sub cmdDisplay_Click()
On Error GoTo Err_cmdDisplay_Click
DoCmd.RunCommand acCmdSaveRecord
Dim stDocName As String

stDocName = "rptTabbedActionPlanCopyReport"
strWhere = "[PatientID]=" & Me![PatientID]
DoCmd.OpenReport stDocName, acPreview, , strWhere
Exit_cmdDisplay_Click:
Exit Sub

Err_cmdDisplay_Click:
MsgBox Err.Description
Resume Exit_cmdDisplay_Click
End Sub

Can anyone find offer any suggestions? Also, just to be sure: is the control name to be used in the Where statement? For example:

"[Unique_Field]=" & Me![Name_of_control]

Thanks
 

Users who are viewing this thread

Back
Top Bottom