UtterAccess.com
We have detected that you are using an unsupported web browser. We recommend you to upgrade your web browser to get the most from UtterAccess forums.
Why should and how can I upgrade?
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Error 3077 syntax error missing operator in expression    
 
   
PNichols
post Jan 27 2005, 04:33 PM
Post #1

UtterAccess Member
Posts: 21



Please help, this error only occurs when I have a facility name with an apostrophe? here is the code?
ub Combo71_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[FacilityName]= '" & Me![Combo71] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub
Thanks,
Paula
Go to the top of the page
 
+
cheekybuddha
post Jan 27 2005, 09:37 PM
Post #2

UtterAccess VIP
Posts: 6,228
From: Telegraph Hill



Hello Paula,
See this link to MSDN library
Go to the section "Moving through a recordset" and a several sub-sections further down is one called "Using Variables in Strings". This explains your problem and below provides a function that will help you get round it("A General Solution for Strings (Well, Almost)")
hth,
d
Go to the top of the page
 
+
cheekybuddha
post Jan 27 2005, 11:22 PM
Post #3

UtterAccess VIP
Posts: 6,228
From: Telegraph Hill



On re-reading the article it seems that the function to deal with apostrophes isn't included, so I have written a function that I imagine will do the same thing.
!--c1-->
CODE
'********************************************************************************
*******
' Procedure : fHandleApostrophe
' DateTime  : 28-01-2005 02:45
' Author    : d
' Purpose   : Deals with apostrophes when passing string values.
'********************************************************************************
*******
'
Public Function fHandleApostrophe(strPass As String) As String
    Dim strRet As String
    
    strRet = strPass
    If InStr(1, strRet, "'", vbTextCompare) > 0 Then
        strRet = "'" & Replace(strRet, "'", "''", , , vbTextCompare) & "'"
    Else
        strRet = "'" & strRet & "'"
    End If
    fHandleApostrophe = strRet
End Function

You can then adjust your code like this:
CODE
Sub Combo71_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[FacilityName]= " & fHandleApostrophe(Me![Combo71])
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

This will not work if there is more than one apostrophe in the FacilityName. I tried playing around with the # sign to deal with multiple apostrophes as suggested in the link but could not get it to work. :(
hth,
d
Go to the top of the page
 
+
PNichols
post Jan 28 2005, 09:29 AM
Post #4

UtterAccess Member
Posts: 21



That did it.
Thank You,
Go to the top of the page
 
+
cheekybuddha
post Jan 28 2005, 09:32 AM
Post #5

UtterAccess VIP
Posts: 6,228
From: Telegraph Hill



Glad it worked,
thumbup.gif
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 21st October 2014 - 10:05 AM