I know there is a lot written on this topic but I can't get it to work. I've tried three methods but still no success. The goal is to be able to have a command button on a form that will open the report filtered only to the ID viewed in the form. I'm using Access 2013. The form is titled "Entry_Form" and shows personnel profile entries. The ID field is "ID". The report is titled "Profiles".
I've tried three different ways by reading in the forums and online. I don't really care how I do this, as long as it works fine for end users. If you can correct my syntax in one of these or give me another way, I would sure appreciate the help! The three code strings I've been trying to make work and their results are pasted below.
Thanks,
jdlantz
>>TRIAL 1 - design a macro to run on event click for the button. My macro design is:
Open Report
Report Name: Profiles
View: Print Preview
Filter Name: [I left this blank]
Where Condition: = [ID]=[Forms]![Entry_Form]![ID]
Window Mode: Normal
>>RESULT: the report opens blank
(NOTE: I tried enclosing some parts of the where condition in "" but didn't get it to work)
>>TRIAL 2 (code builder on event click)
Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "Profiles", acViewPreview, , strWhere
End If
End Sub
>>RESULT: "Run-time error '438': Object doesn't support this property or method"
>>TRIAL 3 - run code builder on event click
Private Sub printrecord_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "Profiles"
strWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPreview, strWhere
End Sub
>>RESULT: "Run-time error '438': Object doesn't support this property or method"