Snowflake68
Registered User.
- Local time
- Today, 15:30
- Joined
- May 28, 2014
- Messages
- 464
Not sure if the title of my post is correct but I am trying to build an SQL query string in VBA which creates a temporary table containing 3 fields. However the field called 'Description' contains Apostrophes which then break the query and produce an error.
The error is a run-time error '3075' Syntax error (missing operator) in query expression "O'Donnel'.
How do I amend the SQL string below so that it takes into account that the Description field may contain apostrophes? Ive played around with this for a while now and just cannot get the syntax correct.
Here is my code:
The error is a run-time error '3075' Syntax error (missing operator) in query expression "O'Donnel'.
How do I amend the SQL string below so that it takes into account that the Description field may contain apostrophes? Ive played around with this for a while now and just cannot get the syntax correct.
Here is my code:
Code:
Dim strSQL2 As String
While [Forms]![frmPreviewSelectionSubForm].frmPreviewSelectionDatasheet.Form.CurrentRecord < [Forms]![frmPreviewSelectionSubForm].frmPreviewSelectionDatasheet.Form.Recordset.RecordCount
strSQL2 = "INSERT INTO TempSortOrder (BIN, ListReference, Description) VALUES ('" & Forms!frmPreviewSelectionSubForm.frmPreviewSelectionDatasheet.Form!BIN & "', '" & Forms!frmPreviewSelectionSubForm.frmPreviewSelectionDatasheet.Form!ListReference & "', '" & Forms!frmPreviewSelectionSubForm.frmPreviewSelectionDatasheet.Form!Description_2 & "');"
DoCmd.RunSQL strSQL2
DoCmd.GoToRecord Record:=acNext
Wend