Problem!! listbox

goldstar19821982

Registered User.
Local time
Yesterday, 20:30
Joined
Feb 17, 2008
Messages
78
Hello All,

I have been trying to resolve a running query

what is happenin is i currently have an order form where i can select an item from a list and press ok this would drop the item within a listbox.
Then if i want to select another item i select the drop down list again and this would show me all the items again to be selected.
I want to limit it so each item can only be selected once, for example
itemID= 01 then next time i select on the list this item would not be ther for this order but would appear for the next order again;

Any help would be much appreciated
 
Make your drop-down three fields, like this:

Code:
ItemID   ItemName   IsSelected
1        ItemA      Yes
2        ItemB      No
3        ItemC      No
.        .          .
.        .          .
X        ItemX      X

Setup that drop-down like this in the properties:

RowSourceType = Table/Query
RowSource = "SELECT * FROM YourTableName WHERE IsSelected = False"
ColumnCount = 3
ColumnWidths = 0;2;0
BoundColumn = 1

Change YourTableName to be the table that has the suggested structure above (or something similar).

When the user selects an item from the drop-down, add that item to your listbox. I assume the listbox is a subset of all items, and the drop-down is the items that haven't been selected. Then, update the table behind the drop-down like this:

Code:
CurrentDb.Execute "UPDATE YourTableName SET IsSelected=True WHERE ItemID= " & YourComboBoxName

The YourTableName above is the same as the first table that the drop-down is based on. Finally, requery the drop-down like this:

Code:
YourComboBoxName.Requery

That's it.

Hopefully, you have Item IDs and everything already setup. If need be, I can whip up a sample of that in 10 minutes if you're confused.
 
moniker if u dont mind, im still a bit confused....
Thank you it is much appreciated
 
Here you go. I made one table (t_Items) and one form (f_Main). Open the form f_Main. It'll work. I made a "Reset" button for you so that you can select stuff from the drop-down and see how it works, and then resetting it will deselect everything and redo the combobox.
 

Attachments

Update

Hi Monika,

I understand what you mean now, but i am getting an error message

Too few parameters expected two?
 
Goldstar,

At first glance here:

Parameter errors usually pop up because there are errors in your syntax blocks somewhere. Try checking all of those first.
 
syntax

This is the line in which the error is found....

CurrentDb.Execute "UPDATE tblitem SET IsSelected = True WHERE itemID = " & cboItemID

I have tried playing around with the syntax, sometimes it shows expected 1, or somtimes 2 and a couple of times it has shown 3

Any ideas would be appreciated
 
If your cboItemID is alphanumeric (stored as text instead of a number), change it to this:

CurrentDb.Execute "UPDATE tblitem SET IsSelected = True WHERE itemID = '" & cboItemID & "'"

That would be the missing parameter.
 
CurrentDb.Execute "UPDATE tblitem SET IsSelected = True WHERE itemID = " & cboItemID
Have you tried different form syntax in place of just the control name?:
Code:
itemID = " & cboItemID
Try:
Code:
forms!form!cboItemID
and then try:
Code:
me.cboItemID (if the code is behind the form itself, that is)
Those work?
 
Hi there,

You are correct the field is alphanumeric, but the too few parameters expected one still appears, even when the code provided has been tried.
Adam - i have tried the suggestions you have made and it does not like these eitehr.
 
Is your IsSelected field set to Yes/No or something else? that's the only other parameter in there.
 
yeah, its set to yes/no. Ive tried everything else not sure what the issue could be
 
It would be easier to upload what you have.

Moniker is good at fixing things like that... :D
 
Not to worry Monikar, i worked out what i was doing wrong, The field IsSelected, was stored in my table as selected only and therefore the error was occuring....

Thanks for all your help, and you too Adam......
 
Glad it was a simple naming thing. I will suggest not using "Selected" as a field name as that's also a keyword. Make it ItemIsSelected or something as now that I think about it, "IsSelected" is also a keyword in certain situations.

At least is wasn't acViewNormal printing your report out or something weird. ;)
 

Users who are viewing this thread

Back
Top Bottom