Single record selection with current data

fireman_gcfd

Registered User.
Local time
Today, 01:50
Joined
Aug 14, 2007
Messages
25
Hello all

I am attempting to fill a report with the current data inputted on my form. I want just a single record selection so when the user finishes inputting their details they can generate a single report for printing. In browsing the forums I have come across many codes which open the report just fine but with No fields filled in. The report is a carbon copy of what the form is and all fields (lots of them) need to be filled in. Am I missing a line of code? Should I be using a SelectRecord line somewhere in there? Here is what I have right now:

Private Sub Command303_Click()
DoCmd.OpenReport "HorizonResponseReport", acViewPreview, , "Incident = " & "Forms![HorizonResponse]![Incident]"
End Sub

The Form name is "HorizonResponse"
The Report name is "HorizonResponseReport"
"Incident" would be the unique seperator between all reports.

hope to hear from you soon

Jaz
 
remove the quotes from & "Forms![HorizonResponse]![Incident]"
as you are not substuting the value from the [Incident] control

At the moment the filter is [Incident] = Forms![HorizonResponse]![Incident]
 
OK that worked..sort of. Al the fields are filled in, but it shows ALL records and not just the one being worked on. I have played around with it and maybe I am missing something simple that is right in front of my eyes...just can't seem to pinpoint it. The database is still small and in construction phase if you (or anyone) wants to see it and play around with it.

Thanks again for your quick reply

Jaz
 
Resolved

I have resolved this problem. many hours of reading and researching but I found it. Thanks for your help. Here is the code in case anyone else runs into the same issue.

Private Sub CommandButton_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 = "[YourField] = """ & Me.[YourField] & """"
DoCmd.OpenReport "YourReportName", acViewPreview, , strWhere
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom