Expected: list separator or )

Oyster

Registered User.
Local time
Today, 15:00
Joined
Nov 16, 2004
Messages
34
I'm new to VB so any help will be appreciated:

I'm getting an Expected: list separator or ) error message when I try to run this code. The problem appears to be my RunSQL statement. Thanks in advance for the help!!!

Private Sub CmdSaveSampleArrival_BatchSampleInfo_Click()

On Error GoTo Err_CmdSaveSampleArrival_BatchSampleInfo_Click
Dim i As Long
For i = 1 To Me.[#Replicate]
DoCmd.RunSQL("Insert Into IndividualSampleInformation (Replicate#,LabBatchCode,LabIndSampleCode) " & _
"Values('" & Cstr(i),Me.LabBatchCode, Me.LabBatchCode & CStr(i) & "');
Next i
Exit_CmdSaveSampleArrival_BatchSampleInf:
Exit Sub

Err_CmdSaveSampleArrival_BatchSampleInfo_Click:
MsgBox Err.Description
Resume Exit_CmdSaveSampleArrival_BatchSampleInf

End Sub
 
DoCmd.RunSQL("Insert Into IndividualSampleInformation (Replicate#,LabBatchCode,LabIndSampleCode) " & _
"Values('" & Cstr(i),Me.LabBatchCode, Me.LabBatchCode & CStr(i) & "');"

Just looking at a glance.. you need to close your quotes... there might also be referencing problems here.. but the quotes would be the biggest problem.

The second biggest problem is that you don't use DoCmd.RunSQL with (). Normally you only use "()" when you're returning a value of a function.
For instance, variable = functionName ("param1",param2)

if function name is just by itself then do:
functionName "param1", param2

3rd) for cleaner programming, put your SQL in a variable

So finished code:
Code:
Dim strSQL As String
Dim i As Long

For i = 1 To Me.[#Replicate]
    strSQL = "Insert Into IndividualSampleInformation ( Replicate#, LabBatchCode, LabIndSampleCode) " & _
             "Values('" & Cstr(i), Me.LabBatchCode, Me.LabBatchCode & CStr(i) & "');"
    DoCmd.RunSQL strSQL
Next i
 
Last edited:
Thanks, but I'm afraid its still not working. I plugged in your code and I'm getting an error at "Values('" & Cstr(i),. The comma after (i) is highlighted and the error says, "Expected : end of statement"

Private Sub CmdSaveSampleArrival_BatchSampleInfo_Click()

On Error GoTo Err_CmdSaveSampleArrival_BatchSampleInfo_Click
Dim i As Long
Dim strSQL As String
For i = 1 To Me.[#Replicate]

strSQL = "Insert Into IndividualSampleInformation ( Replicate#, LabBatchCode, LabIndSampleCode) " & _
"Values('" & Cstr(i),Me.LabBatchCode, Me.LabBatchCode & CStr(i) & "');"
DoCmd.RunSQL strSQL

Exit_CmdSaveSampleArrival_BatchSampleInf:
Exit Sub

Err_CmdSaveSampleArrival_BatchSampleInfo_Click:
MsgBox Err.Description
Resume Exit_CmdSaveSampleArrival_BatchSampleInf

End Sub
 
It's working now! Only had a slight error:
Private Sub CmdSaveSampleArrival_BatchSampleInfo_Click()
On Error GoTo Err_CmdSaveSampleArrival_BatchSampleInfo_Click
Dim i As Long
Dim strSQL As String
For i = 1 To Me![#Replicates]

strSQL = "Insert Into IndividualSampleInformation ( [Replicate#], BatchSampleID, LabBatchCode, LabIndSampleCode) " & _
"Values('" & CStr(i) & "','" & Me!BatchSampleID & "', '" & Me!Text61 & "', '" & Me!Text61 & CStr(i) & " ');"
DoCmd.RunSQL strSQL
Next i

Exit_CmdSaveSampleArrival_BatchSampleInf:
Exit Sub

Err_CmdSaveSampleArrival_BatchSampleInfo_Click:
MsgBox Err.Description
Resume Exit_CmdSaveSampleArrival_BatchSampleInf

End Sub
 
yeah i didn't look at your query, i just copied what you put...and showed you noticeable errors.

glad you got it working.
 

Users who are viewing this thread

Back
Top Bottom