I created a report but of course it displays all of the records from the data table. I want a button on my main form that prompts the user to enter a ID (primary key) and then populate the report with that single record from the data table.
I've seen your video called "Open a Report to Show a Specific Record in Microsoft Access. Display a Single Customer Record" but that is close but not really what I am looking for.
There should be a pop-up prompt asking the user to enter a ID and the return will populate the report.
Sandra Truax
@Reply 4 months ago
'--------------------------------------------------------------
' Replace [YourPrimaryKeyField] with the name of your ID field.
' Replace YourReportName with the name of your report
'--------------------------------------------------------------
Private Sub OpenReportByIDBtn_Click()
Dim vID As Variant
Dim strWhere As String
vID = InputBox("Enter the ID to display on the report:", "Enter Record ID")
' If user cancels or leaves it blank - do nothing
If vID = "" Then Exit Sub
If Not IsNumeric(vID) Then
MsgBox "Please enter a valid numeric ID.", vbExclamation
Exit Sub
End If
Did you rename the button on your FormOpenReportByIDBtn and assign your code to the Click Event?
Patrick SnyderOP
@Reply
4 months ago
This is a continued conversation from 5 days ago.
In response to Alex, I am sorry, I didn't see that you responded to my last response back to Sandra.
I copied/pasted the code that Sandra provided. I did not rename the button on the form, should I and what should it be changed to?
The only changes that I made were per Sandra's instructions:
' Replace [YourPrimaryKeyField] with the name of your ID field.
' Replace YourReportName with the name of your report.
When I check the Property Sheet, the "On Click" has [event procedure] and the code was copied/pasted to codebuilder.
Pat
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visitor Forum.