Trouble with my ABC's

cstanley

Registered User.
Local time
Today, 17:06
Joined
May 20, 2002
Messages
86
Hello all,

I have the following code for a button:

Private Sub Command16_Click()
On Error GoTo Err_Command16_Click
Dim varItem As Variant, strSQL As String
DoCmd.SetWarnings False
If MsgBox("Are you sure you want to append " & Me.[lstRequirements].ItemsSelected.Count & " records?", vbYesNo + vbQuestion, "Appending Records") = vbNo Then Exit Sub
For Each varItem In [lstRequirements].ItemsSelected 'Loop through all selected items in the list box'
strSQL = "insert into [tblDesignUserRequirementsJoin] (DUR,[SystemNumber]) values (" & [lstRequirements].ItemData(varItem) & "," & cboSystemNumber & ")"
DoCmd.RunSQL (strSQL) 'Append a record'
Next 'Move to the next item selected in the list box'
DoCmd.SetWarnings True



Exit_Command16_Click:
Exit Sub

Err_Command16_Click:
MsgBox Err.Description
Resume Exit_Command16_Click

End Sub



It works great when the SystemNumber is in fact a number, but when it is an alphanumeric, it gives me a "parameter missing" error. The field itself is a text field, so it should be able to accomodate the letters and numbers... anyone have any ideas?

Thanks,

Chris
 
Try putting the value of SystmeNumber in quotes i.e.

strSQL = "insert into [tblDesignUserRequirementsJoin] (DUR,[SystemNumber]) values (" & [lstRequirements].ItemData(varItem) & ",'" & cboSystemNumber & "')"
 

Users who are viewing this thread

Back
Top Bottom