Hello everyone.
This problem (or error) involves some minor SQL programming. However the coding is done in and Excel '97 enviroment and involves an Excel userform.
So, I have a syntax error that is occuring after I attempted to insert two new string items into a string variable called strVol.The two additional items are SubPort and PartialMargin.
Let me first walk you through the userform:
1. The user is requested to Add Volume -
Private Sub btnAddVolume_Click()
Dim custName As String
' OpportunityFrame.BackColor = DefaultColor
' VolumeFrame.BackColor = SelectedColor
' NotesFrame.BackColor = DefaultColor
custName = Customer.Text & txtCustomer.Text
If btnAddVolume.Caption <> "Cancel Volume" Then
btnAddVolume.Caption = "Cancel Volume"
If custName <> "" Then
SetVolFields Show:=True
lblInstruction.Caption = " Select Port, Product" & vbCrLf & "and then enter Volume and Margin, then Save"
lblInstruction.ForeColor = vbRed
lblInstruction.Font.Bold = True
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
Else
volCode = volCode + 1
End If
NewVol = True
Port.Text = " " ' must be a valid (existing) Port name
SubPort.Text = " " ' must be a valid (existing) SubPort name
Product.Text = ""
PartialVolume.Text = ""
PartialMargin.Text = ""
VolSaved = 2
VolAdded = True
Port.SetFocus
btnAddVolume.Caption = "Cancel Volume and Margin"
btnSaveVolume.Visible = True
Else
MsgBox "Please select a Customer before adding a new Volume entry", vbOKOnly, "Customer is Required"
Customer.SetFocus
End If
Else
NewVol = False
ClearVolDetails
btnAddVolume.Caption = "Add Volume and Margin"
btnSaveVolume.Visible = False
VolSaved = -1
VolAdded = False
SetVolFields False
End If
volCode = 0
End Sub
A frame that was hidden on the userform then appears and the user populate the various fields namely: Port, SubPort, Product, Volume and then Margin. The user than "Saves The Volume"
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 Port.Text = "*ALL PORTS" Or Port.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, Port, SubPort, Product, PartialVolume, PartialMargin, SALES_ORG) Values (" & _
volCode & "," & lOpCode & ",'" & Replace(Port.Text, "'", "''") & ",'" & Replace(SubPort.Text, "'", "''") & "','" & Replace(Product.Text, "'", "''") & "'," & _
PartialVolume.Text & ",'" & PartialMargin.Text & ",'" & SalesOrgToUseForSave & "')"
addedVol.Add volCode
Else
VolAdded = False
strVol = "UPDATE VOL Set Port = '" & Port.Text _
& "', SubPort.Text" _
& "', SALES_ORG = '" & SalesOrgToUseForSave _
& "', Product = '" & Replace(Product.Text, "'", "''") & "'," _
& "PartialMargin = " & PartialMargin.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 and Margin"
btnDeleteVolume.Visible = False
btnSaveVolume.Visible = False
SetVolFields False
addedVol.Add volCode
ResetFrames
lblInstruction.Visible = False
End If
volCode = 0
End Sub
Now According to the immediate window:
? strVol
INSERT INTO VOL (VolCode, OpCode, Port, SubPort, Product, PartialVolume, PartialMargin, SALES_ORG) Values (23,11,'CARIBBEAN,'AUGUSTA MF ONLY','FUEL OIL',100,'1000,'0733')
which is correct, here CARRIBEAN is an example of a Port and AGUSTA a subport and so fourth. I suspect the double and single qoutes around PartialVolume and PartialMargin are incorrect.
Bookmarks