Syntax Error

  • Thread starter Thread starter skydiver
  • Start date Start date
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.
 
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.
 
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.
 
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]

--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via AccessMonster.com
 
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.

--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via AccessMonster.com
 
Back
Top