Solved

Load combo box based on missing table entries Access VBA

Posted on 2013-01-18
4
352 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

708 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

16 Experts available now in Live!

Get 1:1 Help Now