I have code:
Private Sub RemoveVialsButton_Click()
Dim frm As Form, ctl As Control
Dim varItm As Variant, sel As Variant
Dim id As Variant, rec As Recordset
Dim db As Database, recnum
Set frm = Forms!Remove
Set ctl = frm!VialSearchResultListBox
'For Each varItm In ctl.ItemsSelected
'ctl.ItemData(varItm))
'Next varItm
If Not IsNull(ctl) Then
sel = ctl.ItemsSelected(0)
Else
MsgBox ("No vials selected.")
End If
id = ctl.ItemData(sel)
Set db = CurrentDb
Set rec = db.OpenRecordset("SELECT * FROM Inventory WHERE Inventory.ID = " + id)
MsgBox (rec.RecordCount)
rec.Close
Set rec = Nothing
Set db = Nothing
End Sub
and I get a "Run-time error:'13' Type mismatch" on this line:
Set rec = db.OpenRecordset("SELECT * FROM Inventory WHERE Inventory.ID = " + id)
I'm not sure where I've gone wrong. Any suggestions?
Thanks for the help.
Private Sub RemoveVialsButton_Click()
Dim frm As Form, ctl As Control
Dim varItm As Variant, sel As Variant
Dim id As Variant, rec As Recordset
Dim db As Database, recnum
Set frm = Forms!Remove
Set ctl = frm!VialSearchResultListBox
'For Each varItm In ctl.ItemsSelected
'ctl.ItemData(varItm))
'Next varItm
If Not IsNull(ctl) Then
sel = ctl.ItemsSelected(0)
Else
MsgBox ("No vials selected.")
End If
id = ctl.ItemData(sel)
Set db = CurrentDb
Set rec = db.OpenRecordset("SELECT * FROM Inventory WHERE Inventory.ID = " + id)
MsgBox (rec.RecordCount)
rec.Close
Set rec = Nothing
Set db = Nothing
End Sub
and I get a "Run-time error:'13' Type mismatch" on this line:
Set rec = db.OpenRecordset("SELECT * FROM Inventory WHERE Inventory.ID = " + id)
I'm not sure where I've gone wrong. Any suggestions?
Thanks for the help.