How To Open A Form To A Specific Record In Access 2016 VBA

In this post I am going to give you a basic example of how to open your Access form to a specific record.

This works in all versions of Access, but we are using Access 2016 in this example.

First create “parent and child” forms. In our case, it’s frmCustomers and frmOrders.

Here’s “frmCustomers”

Here’s “frmOrders”

I have it in datasheet format just for viewing purposes. The same principles will apply for “single form”.

When I click the button “View Orders For This Customer”, I get what I asked for.

Here’s the code:

Private Sub btnOrders_Click()
   
    DoCmd.OpenForm "frmOrders", acFormDS, , "CustomerID='" & Me.CustomerID & "'"
End Sub

Basically this says “Open the Orders form in datasheet view, where CustomerID is equal to the customer I am currently viewing”

The quotes are around Me.CustomerID because in this table it is a text value!

Exclude the quotes if you are searching for a number value.

Let me know if you need any specific help.


 

Watch how it’s done:

PS.

Need to pass multiple parameters? Click here






By the way, if you got or are getting value from the VBA information, please give me a tip, thanks!


These posts may help answer your question too...

How To Make An Access Form Time Picker

Here is a relatively easy way to select times for your time entry text boxes. It’s a reusable form that allows you to pick a time from an Access form. There are probably different ways to do this but here is the way I would do it. On the form that has the time fields, […]

How to pick a file to load In VBA

Picking a file to load in your Microsoft App is a very important skill to know. In this blog post you will see how to do it. First you need to set a reference to the MS office object library From VBE editor –> select Tools > MS office object library (click check mark) Sub […]

What is the purpose of the Me keyword in Access VBA?

What does the Me keyword mean? “Me” refers to the Access form currently in focus. Instead of writing out the entire form reference, you can just use the keyword “Me” which is easier. Like: Me.txtbox = “I am a textbox on the form that currently has the focus.” or you can update a label’s caption […]

How do I handle errors in Access VBA code?

I am going to give you the answer to “How do I handle errors in Access VBA code?” In my opinion there are 2 ways to handle errors: 1. Avoid the potential for an error to occur. 2. Handle the error in your code. Number 1 – If you have a control on your form […]

Previous Post

Find Error Line Number in VBA With Erl

Next Post

How To restrict user logon to specific computers