If you have set the Multi Select property of the frmName list box to Simple or Extended, so that the user can select multiple items, the value of the list box will always be Null. You have to loop through the selected items.
Also # is for dates, and you are specifying 2 field names but it looks like you are trying to specify 3 values.
Assuming that frmName is a text field and UserID a number field:
Code: Select all
Dim strSQL As String
Dim itm As Variant
For Each itm In Me.frmName.ItemsSelected
strSQL = "INSERT INTO tblformAccess (frmName,userID) " & _
"VALUES ('" & Me.frmName.ItemData(itm) & "'," & Me.UserID & ")"
CurrentDb.Execute strSQL, dbFailOnError
Next itm
If UserID is a text field like frmName:
Code: Select all
Dim strSQL As String
Dim itm As Variant
For Each itm In Me.frmName.ItemsSelected
strSQL = "INSERT INTO tblformAccess (frmName,userID) " & _
"VALUES ('" & Me.frmName.ItemData(itm) & "','" & Me.UserID & "')"
CurrentDb.Execute strSQL, dbFailOnError
Next itm