472,958 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2872
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.