Solved

Load combo box based on missing table entries Access VBA

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
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.

809 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