comand button

T

Tom Wickerath

Hi Pam,

I have a tutorial that steps one through the process of
creating a Find a Record combo box, using the wizard.
However, this is based on a bound form that simply finds
the selected record in the form's recordset:

http://www.access.qbuilt.com/html/find_a_record.html

My tutorial is not currently designed to open a new form
to the selected value. If you want to do that, you can
use the WhereCondition of the OpenForm method, by passing
in the primary key value for the selected record in the
combo box. The exact coding will depend on whether the
primary key is numeric or text. For example, you could
attach code similar to this to the click event of a
command button (this example is for a numeric primary key):


Dim strCriteria As String

strCriteria = "pkContactID = " & cboFindRecord!pkContactID
DoCmd.OpenForm "YourFromName", WhereCondition:=strCriteria

If your primary key is text, you'll need to include some
single quotes. I think this is the correct syntax for
setting the strCriteria, although I haven't taken the time
to test it (I tend to use surrogate autonumber primary
keys exclusively):

Watch for word wrap. The following should be on one line:

strCriteria = "pkContactID = '" & cboFindRecord!
pkContactID & "'"


Tom
________________________________

I have a comand button that opens a form in print preview
and has a filter that asks a user to enter a location. How
do I add a combo box to let the user select the location
instead of typing it in like a condition. Any helo is help.
 
Top