How to bring up a record using values from 2 combo boxes (1 Viewer)

slaterino

Registered User.
Local time
Today, 02:53
Joined
Dec 2, 2008
Messages
14
Hi,
Can someone help me put together this small VB sub. I need a way that once I click a button, a form will find a specific record using two values from two different combo boxes.

The source of the form is tblSrvRspns. This table includes the fields RspnsID, SrvID and URN. My two combo boxes are cboSrvID and cboURN. They are used to choose the SrvID and URN values desired.

What can I do to make the form go to the particular record using the unique RspnsID once the command button has been pressed. I know I will be using the OnClick event but don't know what function to use. I have used FindRecord before but only when searching for one value. Is it possible to use it to search for two or is there another way of doing this?

Thanks
Russ
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:53
Joined
Aug 30, 2003
Messages
36,125
You should be able to adapt your one value code to find two values. For numeric fields:

...Field1 = " & Me.Control1 & " AND Field2 = " & Me.Control2
 

slaterino

Registered User.
Local time
Today, 02:53
Joined
Dec 2, 2008
Messages
14
Thanks for your help! I'm almost there but having a few problems just getting the final code. I don't know why I find Visual Basic so hard to code.

Anyway, this is my current code, but I am getting an error message on the DoCmd line. I'm presuming this must be because my strFind line is incorrect but I have tried a few different combinations and had no luck yet. Is this how I would use the where statement or do I need to use it differently?

Else
Dim strFind As String
strFind = "[RspnsID] Where ([SrvID] = Me!cboSrvID) AND ([URN] = Me!cboURN)"
DoCmd.FindRecord strFind, acEntire, , , , , False
End If
 

Users who are viewing this thread

Top Bottom