Can I select a record based off a comboBox (1 Viewer)

Jon123

Registered User.
Local time
Today, 14:31
Joined
Aug 29, 2003
Messages
668
I have a form with a combobox that is linked to a box number I want to select a box value and then have that record displayed. I cant get the gotorecord on the after update working on that combobox it that the rightway to go about this?
 

Jon123

Registered User.
Local time
Today, 14:31
Joined
Aug 29, 2003
Messages
668
I'm getting a type mismatch?

Code:
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Kit TOTE Number] = " & Str(Nz(Me![totenumber], 0))
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:31
Joined
Feb 19, 2002
Messages
43,486
Here's a sample that shows how I do this. The form opens empty. You choose a value from the combo and the form is requeried to show the selected record. It takes one line of code and a query with a where clause.
 

Attachments

  • SearchBoxOnFormVer2.accdb
    484 KB · Views: 82

sneuberg

AWF VIP
Local time
Today, 11:31
Joined
Oct 17, 2014
Messages
3,506
I'm getting a type mismatch?

Code:
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Kit TOTE Number] = " & Str(Nz(Me![totenumber], 0))

If [Kit TOTE Number] is a numeric then try
Code:
rs.FindFirst "[Kit TOTE Number] = " & Nz(Me![totenumber], 0)

if it's text the combo box value needs to be in quotes so try

Code:
rs.FindFirst "[Kit TOTE Number] = '" & Nz(Replace(Me![totenumber],"'","''"), 0) & "'"

In either case the Str function shouldn't be necessary. The Replace function is added to escape single quotes. If you don't have that and there is a single quote in the combobox value you will get syntax errors.
 

Users who are viewing this thread

Top Bottom