Solved

Load combo box based on missing table entries Access VBA

Posted on 2013-01-18
4
364 Views
Last Modified: 2013-01-18
Hi all.

I'm working on an Access 2003 form that has the following fields: ItemNo, Packaging, Amount

The table where this data is: myTableA and has the fields: ItemNo, Packaging and Amount.

When the end user enters the ItemNo I want the combo box to show only the packaging options the item does NOT have in myTableA already. Each ItemNo must have 3 packaging levels: EACH, PACK and CASE

For example, let's say in myTableA I have:

ItemNo---Packaging---Amount
123----EACH---5.00
123---PACK---10.00
456---CASE---20.00


So if the end user enters ItemNo: 123, then the combo box should only show CASE.
If the end user enters ItemNo: 456, then the combo box should show EACH and PACK
If the end user enters ItemNo: 789, then the combo box should show EACH, PACK and CASE

Any ideas?

Thank you in advance!
0
Comment
Question by:printmedia
  • 2
  • 2
4 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38793703
In the ItemNo AfterUpdate event:

dim strSQL as string
strSQL = "SELECT Packaging FROM myTableA WHERE ItemNo <> " & Me.ItemNo
Me.MyCombo.Rowsource = strSQL

Open in new window

0
 

Author Comment

by:printmedia
ID: 38793725
Thank you for the reply.

The problem is that EACH, PACK and CASE are not in myTableA until the end user enters it using the form.

So if the ItemNo being entered is not in the table it will not return a Packaging. Or if they are missing any Packaging it will not appear in the combo box because it's not in the table.


I'm referring to the SELECT Packaging portion of your solution:

"SELECT Packaging FROM myTableA"

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38793741
OK -

Create a seperate table for packaging possibilities -- Populate it with EACH, PACK and CASE (you can build on these later as needed with this solution)

And change the SQL like this:

strSQL = "SELECT PackagingType FROM tblPackagingType WHERE PackagingType NOT IN SELECT Packaging FROM MyTableA WHERE ItemNo= " & Me.ItemNo

Code -
dim strSQL as string
strSQL = "SELECT PackagingType FROM tblPackagingType WHERE PackagingType NOT IN SELECT Packaging FROM MyTableA WHERE ItemNo= " & Me.ItemNo
Me.MyCombo.Rowsource = strSQL

Open in new window

0
 

Author Closing Comment

by:printmedia
ID: 38793773
That was it! I added ( ) for the NOT IN select statement.

Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now