Hey guys, I need some major assistance with a listbox I've been fighting with for the last couple of hours.
I have a query (that is selecting from table Pallet) that is populating a listbox. I've also used a Union query to add the text "ALL" at the top of the listbox. Now my issue is that if the user selects all how to have to data that is being passed back in the form. I've tried to find the specific value(s) of the selections but it always seems to be coming back with errors.
Here's the code so far:
DoCmd.SetWarnings False
Dim varData As Variant
Dim myctl As Control
Dim ctllook As Variant
Set myctl = Forms![frm_main].[frm_par_pallet].Form![list_palletkey]
For Each varData In myctl.ItemsSelected
DoCmd.RunSQL "Insert into tbl_lookup_pallet_palletkey (palletkey) select '" & myctl.ItemData(varData) & "'", -1
Next varData
ctllook = DLookup("[palletkey]", "tbl_lookup_pallet_palletkey", "[palletkey]='ALL'"
If ctllook Is Not Null Then
stDocName = "qry_insert_palletkey_lookup"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Else
For Each varData In myctl.ItemsSelected
DoCmd.RunSQL "Insert into tbl_lookup_pallet_palletkey2 (palletkey) select '" & myctl.ItemData(varData) & "'", -1
Next varData
End If
After this is completed the the form does a requery based on looking up the parameters in tbl_lookup_pallet_palletkey2. Maybe this is really roundabout but if anyone has any assistance or suggestions for me I would really appreciate it.
Thanks is advance.
Chris
I have a query (that is selecting from table Pallet) that is populating a listbox. I've also used a Union query to add the text "ALL" at the top of the listbox. Now my issue is that if the user selects all how to have to data that is being passed back in the form. I've tried to find the specific value(s) of the selections but it always seems to be coming back with errors.
Here's the code so far:
DoCmd.SetWarnings False
Dim varData As Variant
Dim myctl As Control
Dim ctllook As Variant
Set myctl = Forms![frm_main].[frm_par_pallet].Form![list_palletkey]
For Each varData In myctl.ItemsSelected
DoCmd.RunSQL "Insert into tbl_lookup_pallet_palletkey (palletkey) select '" & myctl.ItemData(varData) & "'", -1
Next varData
ctllook = DLookup("[palletkey]", "tbl_lookup_pallet_palletkey", "[palletkey]='ALL'"
If ctllook Is Not Null Then
stDocName = "qry_insert_palletkey_lookup"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Else
For Each varData In myctl.ItemsSelected
DoCmd.RunSQL "Insert into tbl_lookup_pallet_palletkey2 (palletkey) select '" & myctl.ItemData(varData) & "'", -1
Next varData
End If
After this is completed the the form does a requery based on looking up the parameters in tbl_lookup_pallet_palletkey2. Maybe this is really roundabout but if anyone has any assistance or suggestions for me I would really appreciate it.
Thanks is advance.
Chris