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.

Offsite Related Information:

“Go Fund Me” Page

($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: ,