Unanswered: Form linking syntax error (use of apostrophe)
I am using the field "CompanyName" as a link between two forms. This has worked perfectly until I came accross a company with an apostrophe in the name. Access thinks the apostrophe in the name of the company is part of the syntax of the openform command. I have easily worked around the problem by using a unique company ID instead of name to link, but I was just wondering if it was possible to fix the problem so I can use companyname again.
The error message recieved when the openform command is run is:
Syntax error (missing operator) in query expression '[CompanyName]='ategic's company".
I have had similar problem when working with fields titled with "#" or other special characters. Any thoughts on possible workarounds would be greatly appreciated.
Public Function FixSingleQuotes(strIn As String) As String
' Double single quotes in a string. Not fast, but doesn't get used
' very often
Dim intI As Integer
Dim strTemp As String
Dim strCh As String
For intI = 1 To Len(strIn)
strCh = Mid(strIn, intI, 1)
If strCh = "'" Then
strTemp = strTemp & "''"
strTemp = strTemp & strCh
FixSingleQuotes = strTemp