473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Reducing the List items on a combo

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
6 2896
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

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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jon | last post by:
I am trying to create a "front end program" to an oracle database and am using visual basic .net to create the program that will accomplish this. What i need to do and what i can't find is the code...
5
by: pdb | last post by:
I want to make something so I can make a grocery list easy and just print it off. I am guessing I would have a drop down list, which would be a list of tables, then select item from the table. For...
4
by: Paul | last post by:
Hi, When should I use a list (in table properties: like Ford;Mercedes;BMW;Audi ) and when should I use a lookup table?? And second question: IF I use a lookup table, should I always make a...
0
by: g18c | last post by:
Hi, i have a class which has a property which is a list of items. I want to be able to set this item list from a set of items (in this case list2 as shown in the code below) from a drop down combo...
1
by: Bremanand | last post by:
Hi am doing my project using Vb 6.0 with ms-access.. am using combo box to select the item by the user.. if the user selecting the item in the combo box without using mouse. My problem is,...
2
by: JweldonH | last post by:
My issue probably has a simple answer. I want to limit a populated combo box to items that are NOT in use in another table. I have a Table with a field that looks up values from another table via...
5
by: Kevin Wilcox | last post by:
In Access 2003 I have a continuous form with a combo. I'm trying to find a way to change the displayed values of the combo depending on whatever value was selected in the combo in the previous...
4
by: sree078 | last post by:
I've a list of items which I bound to multiple combo boxes. In the due course in the code...I had to add an item into one combo box...but I don't want it to be reflected into any other combo...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.