I have the following code that fires in the NotInList Event for my combobox but when someone enters a name with a ' in it I get a run-time error. How can I fix my code to allow for characters?
Dim strsql As String
Dim i As Integer
Dim Msg As String
Dim s As String
'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub
Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Item...")
strsql = fProperCase(NewData, 1)
If i = vbYes Then
s = fProperCase(NewData, 1)
strsql = "INSERT INTO tblCompany(CompanyName) " _
& " SELECT '" & s & "';"
CurrentDb.Execute strsql, dbFailOnError
Response = acDataErrAdded
Response = acDataErrContinue