By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,705 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,705 IT Pros & Developers. It's quick & easy.

Syntax error

P: n/a
I need some fresh eyes to take a look at this code for me and let me
know what it is I'm doing wrong because I keep getting all kinds of
error message with this code. I've had several people help me with this
code and every thing that've told me I've done but for the life of me I
can't seem to get this working right.
First I keep getting "Type mismatch" error message for this line of
code: StrProject = Str(Me!cboProjectID) but if I take out the str and
just have strProject = Me!cboProjectID it's fine.
Second I keep getting "Syntax error(missing operator) in experience in
this line of code:
rst.FindFirst "[cboProjectID] = '" & StrProject & "'" &
"[cboJurisdiction] ='" & StrState

This is the complete code:
Private Sub cmdFind_Click()
Dim rst As DAO.Recordset
Dim StrProject As String
Dim StrState As String

Set rst = Me.RecordsetClone

StrProject = Str(Me!cboProjectID)
StrState = Str(Me!cboJurisdiction)
rst.FindFirst "[cboProjectID] = '" & StrProject & "'" &
"[cboJurisdiction] ='" & StrState
If Not rst.NoMatch Then

MsgBox "Record Found"
Else
MsgBox "Not Found"

End If

Set rst = Nothing

End Sub

I've cross checked my code with other people code and it looks the
same, I also use the help sample code but I keep getting this message.
I know I'm missing something just not sure what.
Any help will be greatly appreciated.

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
For the first issue, can you change it to use CStr() instead of Str():
StrProject = CStr(Me!cboProjectID) ?

For the second, it looks like you are missing the end single quote. I
think it should be:

rst.FindFirst "[cboProjectID] = '" & StrProject & "'" &
"[cboJurisdiction] ='" & StrState & "'"

Hope this helps.

David Hodgkins, MCSD, MCDBA, MCSE
dh*******@jstarsoftware.com
www.jstarsoftware.com

Nov 13 '05 #2

P: n/a
> rst.FindFirst "[cboProjectID] = '" & StrProject & "'" &
"[cboJurisdiction] ='" & StrState
You are concatenating with & when you actually need the word "and" in the
string. You are also missing the ending quote.

rst.FindFirst "[cboProjectID] = '" & StrProject & "' And [cboJurisdiction]
='" & StrState & "'"

Also, why are you converting the cboProjectID to a string? While
cboProjectID may be the name of the combo box on the form, is it the name of
the field in the recordset, same question for cboJurisdiction? How many
columns are in the combo boxes? The value of the combo box will come from
the Bound Column which may not be the displayed column.

--
Wayne Morgan
MS Access MVP
"kufre" <ku********@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...I need some fresh eyes to take a look at this code for me and let me
know what it is I'm doing wrong because I keep getting all kinds of
error message with this code. I've had several people help me with this
code and every thing that've told me I've done but for the life of me I
can't seem to get this working right.
First I keep getting "Type mismatch" error message for this line of
code: StrProject = Str(Me!cboProjectID) but if I take out the str and
just have strProject = Me!cboProjectID it's fine.
Second I keep getting "Syntax error(missing operator) in experience in
this line of code:
rst.FindFirst "[cboProjectID] = '" & StrProject & "'" &
"[cboJurisdiction] ='" & StrState

This is the complete code:
Private Sub cmdFind_Click()
Dim rst As DAO.Recordset
Dim StrProject As String
Dim StrState As String

Set rst = Me.RecordsetClone

StrProject = Str(Me!cboProjectID)
StrState = Str(Me!cboJurisdiction)
rst.FindFirst "[cboProjectID] = '" & StrProject & "'" &
"[cboJurisdiction] ='" & StrState
If Not rst.NoMatch Then

MsgBox "Record Found"
Else
MsgBox "Not Found"

End If

Set rst = Nothing

End Sub

I've cross checked my code with other people code and it looks the
same, I also use the help sample code but I keep getting this message.
I know I'm missing something just not sure what.
Any help will be greatly appreciated.

Nov 13 '05 #3

P: n/a
"kufre" <ku********@yahoo.com> wrote in
news:11*********************@o13g2000cwo.googlegro ups.com:
I need some fresh eyes to take a look at this code for me First I keep getting "Type mismatch" error message for this line of code: StrProject =
Str(Me!cboProjectID) but if I take out the str and just have
strProject = Me!cboProjectID it's fine.
are you trying to convert a number to a string? that should use
the cstr() function., but if cboprojectID is already a string,
that's unnecessary.
Second I keep getting "Syntax error(missing operator) in experience in this line of
code: rst.FindFirst "[cboProjectID] = '" & StrProject & "'" &
"[cboJurisdiction] ='" & StrState
You are missing an operator between "[cboProjectID] = '" &
StrProject and "[cboJurisdiction] ='" & StrState. I suggest the
and operator, which will give you
rst.FindFirst "[cboProjectID] = '" & StrProject & "' AND
[cboJurisdiction] ='" & StrState & "'"

I've cross checked my code with other people code and it looks
the same,
Not exactly the same. :-)

I also use the help sample code but I keep getting this message. I know I'm missing something just not sure what.
Any help will be greatly appreciated.


--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.