?
Solved

Load combo box based on missing table entries Access VBA

Posted on 2013-01-18
4
Medium Priority
?
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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