Docmd.OpenForm With Multiple Parameters

Hi everyone,

I received a question as a result of one of my other posts:

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

please help me. i’ve been trying to solve this problem but didn’t success. how to open a specific record in access 2016 with two conditions? for example i want to open a specific record based on Company Name and Contact Title.

…So it would be helpful to clarify this a bit more.

So what happens if you want to specify more commands in your “wherecondition”?

Here’s a little example:

The following image is of a selection form asking for 2 selections, “Employee” and “Shipped Via”

The form just contains 2 combo boxes, nothing special.

…and it opens this:

…just based on the 2 criteria I asked for on the previous form.

The code behind the command button is pretty straight forward:

DoCmd.OpenForm "frmOrders-20200530", acFormDS, , "[EmployeeID]=" & Me.cboEmployee & " AND [ShipVia]= " & Me.cboShipVia

Here’s another code example based on something totally unrelated:

DoCmd.OpenForm "frmName", acFormDS, , "[FirstName]='Alex' AND [ Class ]= ''2A'"

DoCmd.OpenForm "frmName", acFormDS, , "[FirstName]=" & Me.cboStudentNumber & " AND [ Class ]= '" & Me.cboClassName & "'"

Please note that if the value is text, you need to enclose it in apostrophes, but not when the value is a number.

Let me know if you have questions.




By the way, if you got or are getting value from the VBA information, please click the "Donate" button to give me a small token of your appreciation, thanks!


These posts may help answer your question too...

Learn Access VBA: Understand Tables, Queries, Forms, and Reports

Learn Access VBA: From Zero to Database Hero If you’ve ever opened Microsoft Access and wondered how all the pieces fit together — tables, queries, forms, and reports — this tutorial is made for you. In just a few minutes, you’ll understand how Access works behind the scenes and see how VBA (Visual Basic for […]

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

How to Pick a File in VBA: FileDialog & GetOpenFilename Explained When building Excel VBA applications, you’ll often need to let users pick a file to load in VBA. Instead of hard-coding file paths, you can use built-in dialogs that make file selection easy and user-friendly. VBA offers two main approaches: FileDialog object (flexible, customizable) […]

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 […]


Support these sponsors:
Previous Post

How To Restart A VBA Loop Counter

Next Post

How To Do An Access Export To Excel In VBA