By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,455 Members | 2,306 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,455 IT Pros & Developers. It's quick & easy.

Reducing the List items on a combo

P: n/a
Can someone help on this problem.

I have a combo box of, say three Items, selected from a table that
serves as the lookup: E.g. 1 Earth, 2 Pine, 3 Earth Grave
The combo box is on the subform.

If the user selects any of the item, that item so selected should not
appear in the list again; or
The user should be warned about previous selection.

I dont want the user accidentally selecting the same item out of
error.

Will be grateful if someone can give me a solution.
Jul 29 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You will need a way to indicate that a particular item has been chosen, and
requery the Combo (assuming you are using a Query for the Row Source) to
create a new list. You'll have to determine the scope of this "used, don't
use again" rule and code accordingly... your code will be different if the
scope is "this record", "this session", "this date", or "ever and always".

If you are choosing from a Value List, then it is totally under your
control, and you can provide code in the AfterUpdate event of the Combo to
replace the list after you eliminate the item that was chosen.

Larry Linson
Microsoft Office Access MVP
<he************@gmail.comwrote in message
news:58**********************************@26g2000h sk.googlegroups.com...
Can someone help on this problem.

I have a combo box of, say three Items, selected from a table that
serves as the lookup: E.g. 1 Earth, 2 Pine, 3 Earth Grave
The combo box is on the subform.

If the user selects any of the item, that item so selected should not
appear in the list again; or
The user should be warned about previous selection.

I dont want the user accidentally selecting the same item out of
error.

Will be grateful if someone can give me a solution.

Jul 30 '08 #2

P: n/a

Thank you LARRY,

I quite understand the logic, but sincerely if you can give me an
example.

I am actually using a query as the source, and i want it on the
session i am currently working.

Will be glad if u could help.
Jul 30 '08 #3

P: n/a
On your table have a Field "Selected" as a Yes/No Type

On the open of the form, change all the "Selected" to False
On the close of the form (just to make sure) change all the "Selected" to
False

Your combo box needs a sql somethin like

SELECT Material, MaterialID, Selected FROM MyTable WHERE Selected =False;
2 Columns
Bound Column Column 2
Column Width 5cms; 0 cms

The Update of the Comboboc ("Combo2"

Option Compare Database
Option Explicit

Private Sub Combo2_AfterUpdate()

Dim Mydb As Database
Dim MySet As Recordset
Dim Criteria As String

Set Mydb = CurrentDb
Set MySet = Mydb.OpenRecordset("CoInfo")

Criteria = "MaterialID = " & CLng(Combo2)

With MySet
Do Until !MaterialID = CLng(Combo2)
.MoveNext
Loop
.Edit
!Selected = True 'Then it wont be seen next time
.Update
.Close
Set MySet = Nothing
End With

Combo2.Requery

End Sub

HTH

Phil
<he************@gmail.comwrote in message
news:bc**********************************@l64g2000 hse.googlegroups.com...
>
Thank you LARRY,

I quite understand the logic, but sincerely if you can give me an
example.

I am actually using a query as the source, and i want it on the
session i am currently working.

Will be glad if u could help.

Jul 31 '08 #4

P: n/a
Thank you Phil

However, I still seem to have a problem. After I select an Item, the
item selected does not remain in view in the combo box as usual. It
actually removes the item from the list though. Here is the code in
the After Update

Private Sub Item_AfterUpdate()
Dim Mydb As Database
Dim MySet As Recordset
Dim Criteria As String
Set Mydb = CurrentDb
Set MySet = Mydb.OpenRecordset("L_tbItem")
Criteria = "ItemID = " & CLng(Item)
With MySet
Do Until !ItemID = CLng(Item)
.MoveNext
Loop
.Edit
!Selected = True 'Then it wont be seen next time
.Update
.Close
Set MySet = Nothing
End With
Item.Requery
End Sub

And the sql on the combo Item is

SELECT L_tbItem.Item, L_tbItem.ItemID, L_tbItem.Rate,
L_tbItem.Selected FROM L_tbItem WHERE (((L_tbItem.Selected)=No));

Item is what should be displayed on the combo box after selection.
ItemID is the PK of the table
Rate is associated with an Item which automatically updates the rate
column in the table.

Is there anything I am missing?
Will appreciate if you can help.
Aug 1 '08 #5

P: n/a
Well you gave that ias one alternative in your original post.

If you want to still see the item, remove the "WHERE
(((L_tbItem.Selected)=No))" from the SELECT statement (note that the
semicolon remains)
Change the column count from 2 to 3

Then add the following code on the BeforeUpdate

Private Sub Item_BeforeUpdate(Cancel As Integer)

If Item.Column(2) = True Then
MsgBox "This has already been selected", vbInformation
Cancel = True
End If

End Sub

Phil

<he************@gmail.comwrote in message
news:52**********************************@d45g2000 hsc.googlegroups.com...
Thank you Phil

However, I still seem to have a problem. After I select an Item, the
item selected does not remain in view in the combo box as usual. It
actually removes the item from the list though. Here is the code in
the After Update

Private Sub Item_AfterUpdate()
Dim Mydb As Database
Dim MySet As Recordset
Dim Criteria As String
Set Mydb = CurrentDb
Set MySet = Mydb.OpenRecordset("L_tbItem")
Criteria = "ItemID = " & CLng(Item)
With MySet
Do Until !ItemID = CLng(Item)
.MoveNext
Loop
.Edit
!Selected = True 'Then it wont be seen next time
.Update
.Close
Set MySet = Nothing
End With
Item.Requery
End Sub

And the sql on the combo Item is

SELECT L_tbItem.Item, L_tbItem.ItemID, L_tbItem.Rate,
L_tbItem.Selected FROM L_tbItem WHERE (((L_tbItem.Selected)=No));

Item is what should be displayed on the combo box after selection.
ItemID is the PK of the table
Rate is associated with an Item which automatically updates the rate
column in the table.

Is there anything I am missing?
Will appreciate if you can help.

Aug 1 '08 #6

P: n/a
On Aug 1, 8:22*am, "Phil Stanton" <p...@myfamilyname.co.ukwrote:
Well you gave that ias one alternative in your original post.

If you want to still see the item, remove the "WHERE
(((L_tbItem.Selected)=No))" from the SELECT statement (note that the
semicolon remains)
Change the column count from 2 to 3

Then add the following code on the BeforeUpdate

Private Sub Item_BeforeUpdate(Cancel As Integer)

* * If Item.Column(2) = True Then
* * * * MsgBox "This has already been selected", vbInformation
* * * * Cancel = True
* * End If

End Sub

Phil

<henry.onovw...@gmail.comwrote in message

news:52**********************************@d45g2000 hsc.googlegroups.com...
Thank you Phil
However, I still seem to have a problem. *After I select an Item, the
item selected does not remain in view in the combo box as usual. *It
actually removes the item from the list though. *Here is the code in
the After Update
Private Sub Item_AfterUpdate()
* *Dim Mydb As Database
* *Dim MySet As Recordset
* *Dim Criteria As String
* *Set Mydb = CurrentDb
* *Set MySet = Mydb.OpenRecordset("L_tbItem")
* *Criteria = "ItemID = " & CLng(Item)
* *With MySet
* * * *Do Until !ItemID = CLng(Item)
* * * * * *.MoveNext
* * * *Loop
* * * *.Edit
* * * *!Selected = True * * * * * *'Then it wont be seen next time
* * * *.Update
* * * *.Close
* * * *Set MySet = Nothing
* *End With
* *Item.Requery
End Sub
And the sql on the combo Item is
SELECT L_tbItem.Item, L_tbItem.ItemID, L_tbItem.Rate,
L_tbItem.Selected FROM L_tbItem WHERE (((L_tbItem.Selected)=No));
Item is what should be displayed on the combo box after selection.
ItemID is the PK of the table
Rate is associated with an Item which automatically updates the rate
column in the table.
Is there anything I am missing?
Will appreciate if you can help.
Thank you Phil

Everything is working perfectly well.
Though my client insists on having the item removed in the list.
But we are satisfied with the way it is. This way no two items can be
selected because of the
Cancel = True
However, if there are five items, and this selection is happening on
the sixth record, after all five has been entered, user needs to press
Esc or delete the record.

Thank you for your help.
Aug 1 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.