Goto Record Combo Box Problem

G

Guest

I have a combo box that should goto a record on the form based on the
selected value in the combo box.

Right now all you get is type mismatch error.

Here is the code in the combo box.

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[UserID] = " & Str(Nz(Me![Combo101], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Refresh

TIA,
Tim J
 
G

Guest

If UserID is Numeric then take out the conversion to string
rs.FindFirst "[UserID] = " & Nz(Me![Combo101], 0)

if UserID is Text then surround with single apostrophes
rs.FindFirst "[UserID] = '" & Str(Nz(Me![Combo101], 0)) & "'"
 
G

Guest

I am still getting a type mismatch error

the value is a name and I have enclosed in single quotes, still the same error

any Ideas?

Dennis said:
If UserID is Numeric then take out the conversion to string
rs.FindFirst "[UserID] = " & Nz(Me![Combo101], 0)

if UserID is Text then surround with single apostrophes
rs.FindFirst "[UserID] = '" & Str(Nz(Me![Combo101], 0)) & "'"
Tim J said:
I have a combo box that should goto a record on the form based on the
selected value in the combo box.

Right now all you get is type mismatch error.

Here is the code in the combo box.

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[UserID] = " & Str(Nz(Me![Combo101], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Refresh

TIA,
Tim J
 
G

Guest

I have just tried it myself, the problem is the str & Nz.
Change it to this instead & it works OK
rs.FindFirst "[UserID] = '" & Nz(Me![Combo101], "") & "'"


Tim J said:
I am still getting a type mismatch error

the value is a name and I have enclosed in single quotes, still the same error

any Ideas?

Dennis said:
If UserID is Numeric then take out the conversion to string
rs.FindFirst "[UserID] = " & Nz(Me![Combo101], 0)

if UserID is Text then surround with single apostrophes
rs.FindFirst "[UserID] = '" & Str(Nz(Me![Combo101], 0)) & "'"
Tim J said:
I have a combo box that should goto a record on the form based on the
selected value in the combo box.

Right now all you get is type mismatch error.

Here is the code in the combo box.

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[UserID] = " & Str(Nz(Me![Combo101], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Refresh

TIA,
Tim J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top