Solved

Load combo box based on missing table entries Access VBA

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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