Hello everyone. I am currrently working on a project which has me mostly debugging code. I have a user-form that allows
a user to select from a drop down list a "terminal" (which by-the-way is a list of names of various physical plant facilities:
e.g. St. John's). After selecting from the drop-down list and after entering other data the user will then press a button called "Save Volumes".
There is a problem however when a user selects a terminal name that has an apostrophe in it, for instance St. John's, it causes the following error:
"Syntax error (missing operator) in query expression ...."
Now just so you know the actual list of terminal name is stored in a Access database, the 1997 version. Below is the code in question
with an error pointing to the error. Any help is appreciated.
The "Save Volumes" button code is below:
![]()
Private Sub btnSaveVolume_Click() Dim custName As String Dim strVol As String Dim SalesOrgToUseForSave As String custName = Customer.Text & txtCustomer.Text VolSaved = -1 If ValidateVolume Then ' validate the Volume entries 'if Valid, then add this set of entries to the Opportunity Details grid SalesOrgToUseForSave = Sheets(VALIDATIONS).Range("CurrentSalesOrg") If Terminal.Text = "*ALL TERMINALS" Or Terminal.Text = "*OTHER" Then SalesOrgToUseForSave = "0000" If NewVol Then If volCode = 0 Then Dim rs As New ADODB.Recordset rs.Open "Select Max(VolCode) + 1 as VCode from VOL", VolConn If rs!VCode & "" = "" Then volCode = 1 Else volCode = rs!VCode Set rs = Nothing End If End If VolAdded = True strVol = "INSERT INTO VOL (VolCode, OpCode, Terminal, Product, PartialVolume, SALES_ORG) Values (" & _ volCode & "," & lOpCode & ",'" & Terminal.Text & "','" & Replace(Product.Text, "'", "''") & "'," & _ PartialVolume.Text & ",'" & SalesOrgToUseForSave & "')" addedVol.Add volCode Else VolAdded = False strVol = "UPDATE VOL Set Terminal = '" & Terminal.Text _ & "', SALES_ORG = '" & SalesOrgToUseForSave _ & "', Product = '" & Replace(Product.Text, "'", "''") & "'," _ & "PartialVolume = " & PartialVolume.Text _ & " where VolCode = " & volCode End If VolConn.Execute strVol <------ Error FillOppDetails ClearVolDetails VolSaved = 1 btnAddVolume.Visible = True btnAddVolume.Caption = "Add New Volume" btnDeleteVolume.Visible = False btnSaveVolume.Visible = False SetVolFields False addedVol.Add volCode ResetFrames lblInstruction.Visible = False End If volCode = 0 End Sub
Bookmarks