Is it possible to create a public sub that handles a specific error code? I have multiple text fields and update buttons on my form, which are used to replace text in certain tables with the strings from the text boxes.
However, if the string in the text box contains an apostrophe, the error code '3075' is given. I don't want to write an error handler for each sub; is it possible to create a public sub and call it if error 3075 is encountered?
E.G - this is what the public sub might look like:
Public Sub ErrHandler()
If Err.Number = 3075 Then
MsgBox("You can't use apostrophes in the text box")
End If
End Sub
Then something like this will go in each sub that has a textbox:
On Error Call ErrHandler
I have tried the above code, it doesn't work. Was just wondering if anybody has any other ideas or workarounds for this?
EDIT:
Here is the code for the update button. It replaces the selected item in the listbox(TelephoneList) with the strings from the text boxes ('txtTele' and 'txtDescription;)
The listbox displays items from the 'LPA Telephone' Table.
Private Sub UpdateTelephoneButton_Click()
If Not IsNull(txtTele) And Not IsNull(TelephoneList.Column(0)) Then
CurrentDb.Execute "UPDATE [LPA Telephone] " & _
"SET [Telephone] = '" & Me.txtTele & "'" & _
", [Description] = '" & Me.txtDescription & "'" & _
"WHERE [ID] = " & Int(TelephoneList.Column(0)) & ""
TelephoneList.Requery
End If
End Sub
Public Function RQuote(s As Variant) As Variant RQuote = Replace(s, """", """""") End Function
That would replace them and allow users to use apostrophe's. – Zaider