runtime error 3077 (1 Viewer)

S

shieldk

Guest
Hi all,

I have this statement in my code
<<Me.RecordsetClone.FindFirst "[Company] = '" & Me![ComboCompany] & "'">>

It runs fine for all records except fields contains the ' apostrophe character, eg "David's house" or "I'm"

Any help or suggestions are most appreciated.
 

Rich@ITTC

Registered User.
Local time
Today, 09:48
Joined
Jul 13, 2000
Messages
237
Hi Shieldk

You could create a function to deal with Apostrophes and then call the function from your form.

Here is the Apostrophe function (not something I created ... so apologies to the actual author but I cannot remeber where I found it).

----------------------------------------------
Public Function Apostrophe(strSFieldString As String) As String
' Comments :
' Parameters : strSFieldString -
' Returns : String -
' Created :
' Modified :
'
' --------------------------------------------------------
On Error GoTo Err_Apostrophe

If InStr(strSFieldString, "'") Then
Dim intILen As Integer
Dim intIi As Integer
Dim intApostr As Integer
intILen = Len(strSFieldString)
intIi = 1

Do While intIi <= intILen
If Mid(strSFieldString, intIi, 1) = "'" Then
intApostr = intIi
strSFieldString = left(strSFieldString, intApostr) & "'" & _
right(strSFieldString, intILen - intApostr)
intILen = Len(strSFieldString)
intIi = intIi + 1
End If
intIi = intIi + 1
Loop
End If
Apostrophe = strSFieldString

Exit_Apostrophe:
Exit Function

Err_Apostrophe:
MsgBox Err.Description & _
" - (Error No:" & Err.Number & ")"
Resume Exit_Apostrophe

End Function
-----------------------------------------------

In your code you then call this public function eg.

Dim strCompanyName As String

strCompanyName = Apostrophe(Me![cboCompany])
Me.RecordsetClone.FindFirst "[Company] = '" & strCompanyName & "'"

HTH

Rich Gorvin
 
S

shieldk

Guest
Hi Rich,

Thanks for your suggestion, the method works. However I think there are some error in the function because although it solve the runtime error, it cannot retrieve any record that has the apostrophe character.

Hi Harrisw,

The link you've given is not working
.
 

Rich@ITTC

Registered User.
Local time
Today, 09:48
Joined
Jul 13, 2000
Messages
237
Hi shieldk

I have just tried the Apostrophe code within my own database again and it works perfectly. I am sorry that you can't get it to retrieve records with apostrophes ... but I think there must be some other reason why this is the case!

Good luck in your attempts at getting it to work.

Rich Gorvin
 

Users who are viewing this thread

Top Bottom