.findfirst Recordset

  • Thread starter Thread starter Knick
  • Start date Start date
K

Knick

I am getting an error when I run this function; at line 2 I am getting an
Error #3077 missing operator in expression. Since I am new to VBA programming
I wanted to get some help with it, can anyone point out the syntax error in
this ?

1 function New()
2 Set y = db.openrecordset("table", DB_OPEN_DYNASET)
3 y.FindFirst "fieldName " & Globalvariable & " "
4 rstshDM.Close
5 End Function

Thanks in Advance
Knick
 
Knick said:
I am getting an error when I run this function; at line 2 I am
getting an Error #3077 missing operator in expression. Since I am new
to VBA programming I wanted to get some help with it, can anyone
point out the syntax error in this ?

1 function New()
2 Set y = db.openrecordset("table", DB_OPEN_DYNASET)
3 y.FindFirst "fieldName " & Globalvariable & " "
4 rstshDM.Close
5 End Function

Thanks in Advance
Knick

It's not clear to me what that function is supposed to do, but your
syntax error is because you need to use a comparison operator of some
sort (such as =, <, >, or <>) in the FindFirst criterion. For example,

Set y = db.openrecordset("table", dbOpenDynaset)
y.FindFirst "fieldName = " & Globalvariable

If the field [fieldName] is a text field, you need to put quotes around
the value you get from Globalvariable, like this:

y.FindFirst "fieldName = '" & Globalvariable & "'"

or this:

y.FindFirst "fieldName = " & Chr(34) & Globalvariable & Chr(34)

The first version would work if Globalvariable doesn't contain a
single-quote character ('). The second would work if it contains a
single-quote, but not a double-quote ("). If it might contain either,
you need to do something more complicated, like this:

y.FindFirst "fieldName = " & _
Chr(34) & _
Replace(Globalvariable, Chr(34), Chr(34) & Chr(34)) & _
Chr(34)
 
I am getting an error when I run this function; at line 2 I am getting an
Error #3077 missing operator in expression. Since I am new to VBA programming
I wanted to get some help with it, can anyone point out the syntax error in
this ?

1 function New()
2 Set y = db.openrecordset("table", DB_OPEN_DYNASET)
3 y.FindFirst "fieldName " & Globalvariable & " "
4 rstshDM.Close
5 End Function

Thanks in Advance
Knick

<low whistle>
Couple of things going on here.

Are you declaring these variables anywhere?
Where did you Set and Open rstshDM?
"table" is a terrible name for a Table.

Looking up FindFirst in the Help file is a very good way to see the syntax not
only for FindFirst but for how to open a recordset as well.

Hope this helps,
RD
 
Back
Top