Hlep I am really stuck - type mismatch in criteria expression

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to make a form that finds records from a table and displays them
in a form.
I have created a form and placed the required fields onto the form. I have
created an unbound combo box and added an expression to the on change
property.The code looks like this
Private Sub Combo8_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

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

It is supposed to look in a field called vrm ("text" type in the table
concerned), and then compare it to the value in the combo box ( combo8). It
then displays all the fields required from the table in question on the form.

It works so long as the values in the vrm field in the table are numbers, it
falls over if any vrm value if a string. It states type mismatch in crtieria
expression. W

Can any one suggest the changes required to the code to make this work with
string values?
 
Change this line:
rs.FindFirst "Str([vrm]) = '" & Str(Nz(Me![Combo8], 0)) & "'"

You need to surround text values with single quotes...
 
There is no need for the Str function and that is what is causing the type
mismatch. The Str function is expecting a numeric value as its argument. It
should be like this:

rs.FindFirst "[vrm] = '" & Me![Combo8] & "'"

The Nz function in the search would be meaningless unless you have a record
where vrm is = "0" (as a string)
Also, notice the quotes. They are necessary when searching for a text value.
 
Back
Top