
StrSQL = "Insert into tblCrewMember (LastName) values ('" & strCriteria & "')" StrCriteria = Sheets("Update").Range("B10") StrWord = Left(strWord, x - 1) & Chr(39) & Chr(39) & Right(strWord, Len(strWord) - (x)) X = InStr(x + 2, strWord, "'") 'Find position of apostrophes

StrConnectionstring = "DRIVER= SERVER=" & strServer & " Trusted_Connection=yes DATABASE=" & strDBase 'Windows authenticationįunction fRemoveApostrophe(strWord As String)

Public connDB As New ADODB.Connectionĭim strServer, strDBase, strUser, strPWD As String Use the menu items >Tools >References to reference ADO libraries.Ĭopy the code below into the module.

This article assumes the reader has the Developer ribbon displayed and is familiar with the VBA Editor. This article explores the use of a customised VBA function to resolve this anomaly. An escape character is required for the apostrophe after Brown. Inserting ‘Mrs Brown’s Boys’ into a database table will fail since the three single quotes imply two strings, one of which is incomplete. SQL Server uses pairs of single quotes to identify the start and end of a string.
