Syntax Error

S

skydiver

I am having a problem with the syntax for the following code.

'''If specified a Work Area
If Not IsNothing(Me.cboWorkArea) Then
varWhere = (varWhere + " AND ") & "[WorkArea] LIKE '*" &
Me.cboWorkArea & "*'"
End If

'''If specified a Location
If Not IsNothing(Me.cboLocation) Then
varWhere = (varWhere + " AND ") & "[Location] LIKE '*" &
Me.cboLocation & "*'"
End If


Each varwhere get their values from a combo box. The codes actually works
fine as long as neither of the two fields have a value with an apostrophe
i.e., Warden's. The search works fine when the apostrophe is removed.


Could someone help me with this please?

Thanks in advance.
 
J

J_Goddard via AccessMonster.com

Hi -

Change your delimiting single-quotes to double double-quotes,
i.e. each ' becomes "" For example:

'''If specified a Work Area
If Not IsNothing(Me.cboWorkArea) Then
varWhere = (varWhere + " AND ") & "[WorkArea] LIKE ""*" & Me.
cboWorkArea & "*"""
End If



John


I am having a problem with the syntax for the following code.

'''If specified a Work Area
If Not IsNothing(Me.cboWorkArea) Then
varWhere = (varWhere + " AND ") & "[WorkArea] LIKE '*" &
Me.cboWorkArea & "*'"
End If

'''If specified a Location
If Not IsNothing(Me.cboLocation) Then
varWhere = (varWhere + " AND ") & "[Location] LIKE '*" &
Me.cboLocation & "*'"
End If

Each varwhere get their values from a combo box. The codes actually works
fine as long as neither of the two fields have a value with an apostrophe
i.e., Warden's. The search works fine when the apostrophe is removed.

Could someone help me with this please?

Thanks in advance.
 
S

skydiver

When I changed the delimiting single quotes to double-quote I received an
type mismatch error and the frolling code is highlighted:

varWhere = (varWhere + " AND ") & "[WorkArea] LIKE " * " & Me.cboWorkArea &
" * ""



J_Goddard via AccessMonster.com said:
Hi -

Change your delimiting single-quotes to double double-quotes,
i.e. each ' becomes "" For example:

'''If specified a Work Area
If Not IsNothing(Me.cboWorkArea) Then
varWhere = (varWhere + " AND ") & "[WorkArea] LIKE ""*" & Me.
cboWorkArea & "*"""
End If



John


I am having a problem with the syntax for the following code.

'''If specified a Work Area
If Not IsNothing(Me.cboWorkArea) Then
varWhere = (varWhere + " AND ") & "[WorkArea] LIKE '*" &
Me.cboWorkArea & "*'"
End If

'''If specified a Location
If Not IsNothing(Me.cboLocation) Then
varWhere = (varWhere + " AND ") & "[Location] LIKE '*" &
Me.cboLocation & "*'"
End If

Each varwhere get their values from a combo box. The codes actually works
fine as long as neither of the two fields have a value with an apostrophe
i.e., Warden's. The search works fine when the apostrophe is removed.

Could someone help me with this please?

Thanks in advance.
 
J

J_Goddard via AccessMonster.com

You didn't use the double double-quotes correctly; the quote following LIKE
should be double, and there should be a double following the last *. I
changed the syntax a bit:

varWhere = varWhere & " AND [WorkArea] LIKE ""*" & Me.cboWorkArea & "*"""

John

When I changed the delimiting single quotes to double-quote I received an
type mismatch error and the frolling code is highlighted:

varWhere = (varWhere + " AND ") & "[WorkArea] LIKE " * " & Me.cboWorkArea &
" * ""
[quoted text clipped - 30 lines]
 
S

skydiver

You are absolutely correct. I was only 1/3 awake at the time. I am sorry
for not paying attention and wasting your time. If I would have waited ten
minutes I would have saved us both some time.


J_Goddard via AccessMonster.com said:
You didn't use the double double-quotes correctly; the quote following
LIKE
should be double, and there should be a double following the last *. I
changed the syntax a bit:

varWhere = varWhere & " AND [WorkArea] LIKE ""*" & Me.cboWorkArea & "*"""

John

When I changed the delimiting single quotes to double-quote I received an
type mismatch error and the frolling code is highlighted:

varWhere = (varWhere + " AND ") & "[WorkArea] LIKE " * " & Me.cboWorkArea
&
" * ""
[quoted text clipped - 30 lines]
Thanks in advance.
 

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