TheSearcher
Registered User.
- Local time
- Today, 02:23
- Joined
- Jul 21, 2011
- Messages
- 356
I'm getting a type mismatch error in the following code on the "Set lstname = txt_CurrentListBox" line.
I realize that lstname is an object (listbox) and txt_CurrentListBox is a textbox holding a string so the error makes sense. However, what can I do to use a variable for the listbox name so that this can work? Does anyone know the correct syntax?
Your help is much appreciated!
I realize that lstname is an object (listbox) and txt_CurrentListBox is a textbox holding a string so the error makes sense. However, what can I do to use a variable for the listbox name so that this can work? Does anyone know the correct syntax?
Your help is much appreciated!
Code:
Dim lstname As listbox
Dim varItem As Variant
Set lstname = txt_CurrentListBox
For Each varItm In lstname.ItemsSelected
sql1 = "Insert into tbl_Note_PT_Objective_1 (Note_ID, [Category], Options) "
sql1 = sql1 & "select " & Globals.glb_NoteID & ", '" & txt_Category & "', '" & lstname.ItemData(varItm) & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL sql1
DoCmd.SetWarnings True
Next varItm