Computer Learning Zone CLZ Access Excel Word Windows

Life is not fair. Get used to it.

-Bill Gates
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Button to open a report to
Patrick Snyder 

4 months ago
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

    strWhere = "[YourPrimaryKeyField] = " & CLng(vID)

    DoCmd.OpenReport "YourReportName", acViewPreview, , strWhere

End Sub
Patrick Snyder OP  @Reply  

4 months ago
I copied the code that you provided, updated the ID Field and Report Name but when I click the button, it doesn't do anything.
Alex Hedley  @Reply  
           
4 months ago
Did you rename the button on your Form OpenReportByIDBtn and assign your code to the Click Event?
Patrick Snyder OP  @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

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 7:01:15 AM. PLT: 1s