
Originally Posted by
OFA
Hello,
I am having a problem linking a button on my form to print a single report of the entry that I just entered on the form. I have created the button and it links properly to the report however when I click the button the report comes up blank. For some reason it seems that the fields are not linked properly between the form and the report? When I open up the report manually all the report appear to be there and does not encounter the same problem, all the information is displayed. Below is the code I used for the button:
Code:
Private Sub cmdPrint_Click()
Dim strReport As String
Dim strWhere As String
If Me.Dirty Then Me.Dirty = False 'save the record
strReport = "Renewal Plan Checklist"
strWhere = "[Plan #] = " & Me![Plan #]
DoCmd.OpenReport strReport, acPreview, , strWhere
End Sub
The spaces in the field names are going to be problems, also your ID should be used (PK)
Code:
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 = "[YourID] = " & Me.[YourID]
DoCmd.OpenReport "Renewal Plan Checklist", acPreview, , strWhere
Me.Requery
End If