473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Filter a combobox based on another combobox

DJRhino1175
221 128KB
Table set up that feed the comboboxes:

SAPFinishedPartNo
OldPartNo
SAPCompNo
OldCompNo

Combobox Name on form:

1st combobox:cboSAPNNo
2nd Combobox: cboComp

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSAPNNoID_AfterUpdate()
  2.  
  3. With Me![cboComp]
  4.     If IsNull(Me!cboSAPNNo) Then
  5.       .RowSource = ""
  6.     Else
  7.       .RowSource = "SELECT [SAPCompNo] " & _
  8.                    "FROM tblPartNoList " & _
  9.                    "WHERE [SAPFinishedPartNo]=" & Me!SAPCompNo
  10.     End If
  11.     Call .Requery
  12.   End With
  13. End Sub
I believe I have something in the wrong order or jumbled...This is my first time trying this. I tried to follow an article on this forum, but apparently mucked it up.

I need to select a number from the 1st combobox and have it filter the 2nd combobox that match the 1st box.

I have all 4 (SAPFinishedPartNo; OldPartNo; SAPCompNo; oldCompNo) in an embedded query feeding the comboboxes.

On the 1st combobox I have SAPFinishedPartNo; OldPartNo visible to the user with SAPFinishedPartNo as the bound column.

On the 2nd combobox I have SAPCompNo; oldCompNo visible with SAPCompNo as the bound column.

Thanks for the help and hopefully I was fairly clear on what I was looking for....
Nov 26 '19 #1

✓ answered by twinnyfo

Line 3 above has an asterisk before the quotes, unless you are just pointing out where it breaks.

Also, you should have a space after the closing square brace in line 1:

Expand|Select|Wrap|Line Numbers
  1. .RowSource = _
  2.     "SELECT [SAPCompNo] " & _
  3.     "FROM tblPartNoList " & _
  4.     "WHERE [SAPFinishedPartNo]='" & Me.cboSAPNNo & "'"
No need for any parentheses (that's an MS Accessism, which is totally unnecessary with only one criteria in the WHERE clause).

Hope this hepps!

17 3025
NeoPa
32,556 Expert Mod 16PB
Hi DJ.

You've done a decent job explaining but I suspect you've been a little sloppy with names. Your code indicates a ComboBox of cboSAPNNOID but your explanation calls it cboSAPNNO. In conversation such precision is rarely important. In computer terms it's critical. I don't expect that's directly related to this not working but there's more missing that makes it hard to steer you accurately.

I know. It's very hard for you to know what is necessary to include when you're in the position before you understand it well enough to do it without help anyway. Catch 22!

Reading between the lines I would guess what you're actually trying to do is a form of cascaded filtering such that you want cboCompID to contain a list of [SAPCompNo]s where the [SAPFinishedPartNo] equals the value already selected in cboSAPNNoID if there is one.

It helps to know whether cboSAPNNoID is a string or numeric value. We don't know that so I'll just comment that the quotes (') should be removed from the following suggested code unless the value is a string :
Expand|Select|Wrap|Line Numbers
  1. .RowSource = "SELECT [SAPCompNo] " _
  2.            & "FROM [tblPartNoList] " _
  3.            & "WHERE ([SAPFinishedPartNo]='" & Me.cboSAPNNoID & "')"
See how that works in place of lines #7 through #9.
Nov 26 '19 #2
DJRhino1175
221 128KB
NeoPa,

Sorry I thought I had updated and removed all of the "ID"'s from this post....

This is the coda as it stands now
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSAPNNo_AfterUpdate()
  2.  
  3. With Me![cboComp]
  4.     If IsNull(Me!cboSAPNNo) Then
  5.       .RowSource = ""
  6.     Else
  7.       .RowSource = "SELECT [SAPCompNo] " & _
  8.                    "FROM tblPartNoList " & _
  9.                    "WHERE [SAPFinishedPartNo]=" & Me!cboSAPNNo
  10.     End If
  11.     Call .Requery
  12.   End With
  13. End Sub
I get a data type mismatch in criteria expression.

I looked up in the table and all are short text (SAP numbers are all numeric, but we also have alphanumeric in there to, so I made them all short text)

So now when I enter a SAP number in the combobox "cboSAPNNo", I get the above error when opening the dropdown of the combobox "cboComp"
Nov 27 '19 #3
DJRhino1175
221 128KB
I did a little more work on it and got rid of the data mismatch, but now nothing shows up in "cboComp" when I pick a number/Text from "cboSAPNNo" So We/I must be getting closer and it's just not seeing the selection from "cboSAPNNo"

Here is where it stands now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSAPNNo_AfterUpdate()
  2.  
  3. With Me![cboComp]
  4.  
  5.     If IsNull(Me!cboSAPNNo) Then
  6.  
  7.       .RowSource = ""
  8.  
  9.     Else
  10.  
  11.       .RowSource = "SELECT [SAPCompNo]" & _
  12.                     "FROM tblPartNoList " & _
  13.                     "Where [SAPFinishedPartNo]=""[cboSAPNNo]"" "
  14.     End If
  15.  
  16.     Call .Requery
  17.  
  18.   End With
  19.  
  20. End Sub
Nov 27 '19 #4
NeoPa
32,556 Expert Mod 16PB
Hi DJ.

I suspect if you go back to my post and use that as a template it will work perfectly without any problems. Of course you'll need to pay close attention to how you do that this time ;-)
Nov 28 '19 #5
DJRhino1175
221 128KB
NeoPa,

I copied exactly how you have it and it comes out blank. It should list 10 items.Here is the code exactly as its entered.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSAPNNo_AfterUpdate()
  2.  
  3. With Me![cboComp]
  4.  
  5.     If IsNull(Me!cboSAPNNo) Then
  6.  
  7.       .RowSource = ""
  8.  
  9.     Else
  10.  
  11.       .RowSource = "SELECT [SAPCompNo]" & _
  12.                     "FROM tblPartNoList " & _
  13.                     "Where [SAPFinishedPartNo]=""[cboSAPNNo]"" "
  14.     End If
  15.  
  16.     Call .Requery
  17.  
  18.   End With
  19.  
  20. End Sub
Dec 3 '19 #6
DJRhino1175
221 128KB
NeoPa,


Just noticed I entered it wrong from what you put, but now I get a syntax error when compiling.

Expand|Select|Wrap|Line Numbers
  1. .RowSource = "SELECT [SAPCompNo]" & _
  2.                     "FROM tblPartNoList " & _
  3.                     * "WHERE ([SAPFinishedPartNo]='" & Me.cboSAPNNo & "')"
Dec 3 '19 #7
twinnyfo
3,653 Expert Mod 2GB
Line 3 above has an asterisk before the quotes, unless you are just pointing out where it breaks.

Also, you should have a space after the closing square brace in line 1:

Expand|Select|Wrap|Line Numbers
  1. .RowSource = _
  2.     "SELECT [SAPCompNo] " & _
  3.     "FROM tblPartNoList " & _
  4.     "WHERE [SAPFinishedPartNo]='" & Me.cboSAPNNo & "'"
No need for any parentheses (that's an MS Accessism, which is totally unnecessary with only one criteria in the WHERE clause).

Hope this hepps!
Dec 3 '19 #8
DJRhino1175
221 128KB
Twinnyfo,

That did it. My only issue is that I have 2 visible columns for the cboSAPNo, but after the filter it only shows the bound column. I was figuring the second column would show up. Do I need to add this into the .recordsource? I did try changing it to:

Expand|Select|Wrap|Line Numbers
  1. "SELECT [SAPCompNo], [OldCompNo] "
But this did not work, just came out blank again.

I know this wasn't part of the original question but I "assumed" it would automatically show.

Thanks for the fix on the last part.
Dec 3 '19 #9
twinnyfo
3,653 Expert Mod 2GB
I'll allow as a follow-on question within this thread, as it is an easy resolution (should be) and is directly related to your particular issue.

If you have a Combo Box with two columns, typically, the first column is the bound column and is numerical (and index) and the second column shows the text referred to in the index. For your ColumnWidth property, you set it to 0"; 1". This means that the first column is "hidden", and the second is one inch wide (displayed).

Hope this hepps.
Dec 4 '19 #10
DJRhino1175
221 128KB
Twinnyfo,

I have it set up like this already. If I comment out the filter in VBA it shows exactly the way it's supposed to. I have it set as (1.25";2"), Column count 2, Column Heads=Yes, Bound column 1. This is why I had to ask the follow up question, I figured it would show...
Dec 4 '19 #11
twinnyfo
3,653 Expert Mod 2GB
I'm not sure what you mean by "comment out the filter".

Also, typically, your bound column is not shown, because it is just a numerical value. But, based upon the example in Post #6, you only have one column being returned from the query, so, I'm not exactly sure what you are chasing after....
Dec 4 '19 #12
DJRhino1175
221 128KB
When you put ' in front of a line of code..."Comment out"

I need:

SAPCompNo - Bound
OldCompNo - unbound but visible in dropdown

I uploaded 2 pictures to show you what I need when filtered and what it is doing currently filtered.
Attached Images
File Type: jpg Pic of both Columns need.jpg (61.4 KB, 158 views)
File Type: jpg Pic when filtered.jpg (59.1 KB, 153 views)
Dec 4 '19 #13
NeoPa
32,556 Expert Mod 16PB
Hi DJ.

You've been busy in my absence.

I try to get my suggestions right but I do struggle to see properly so sometimes I include a * when it should be an & :-( Nevertheless, you should find that the original suggestion, if copied accurately, gives you the result you require.

That if copied accurately part is so very important. Copy/Paste is your friend.

Thanks, as always, to Twinny for stepping in and illustrating again what you needed.

I would add that I always use parentheses in my WHERE clauses. Not that it's absolutely necessary; simply that it helps to clarify what's what - particularly when trying to follow VBA code that is used to create the SQL. It's more of a style thing than necessary syntax obviously.
Dec 4 '19 #14
DJRhino1175
221 128KB
NeoPa,

We got the filter working perfectly, but for some reason when it is filter the second column isn't present.
Dec 4 '19 #15
twinnyfo
3,653 Expert Mod 2GB
Your SQL is only asking for one column.
Dec 4 '19 #16
DJRhino1175
221 128KB
I got it to work, I added , [OldCompNo], this time it seem to work, not sure what I did differently...but hey it worked, that's all that matters. Now I can go on vacation for the rest of the month.

Thanks for yours and Neopa's help and merry christmas and Happy new years to you both.
Dec 5 '19 #17
twinnyfo
3,653 Expert Mod 2GB
Glad we could hepp!

Merry Christmas and Happy New Year to you as well!
Dec 9 '19 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Pete | last post by:
I have a combobox which is used to select records, which is satisfactory at the moment. However, a second user is going to start using this database and there will be 1600 records. This makes...
6
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
10
by: ZaphodBBB | last post by:
HI I have a form with 2 comboBoxes. The first comboBox gives me a list of customers to select from. I would like to have the second comboBox populated with the names of Departments. I only want...
2
by: jujubean | last post by:
I have a form with five comboboxes. In the first, the user can select one of four items. The other four comboxes are hidden. Based on the selection made in combobox one, I would like one of the...
6
by: pouj | last post by:
what i want to do is basically have form where my selection in the combox make the diffrence with what the form reports. this is what the underlying informaion is.... software is access 2007 i...
0
by: Moorthi chinna | last post by:
how to reload combobox in datagridview based on combobox selection in datagridview?
3
by: Poongs | last post by:
hi <select name="jobCode" class=comboBox id="jobCode"> <?php $jobCodeQuery="select * from jobcodecreation"; $jobcodeResult = mysql_query($jobCodeQuery); echo "<option...
7
by: sheela gupta | last post by:
I want to populate the combobox based on the selected item in the first combobox The following code is written in vb.net 2008 Public Class Form1 Sub fillcombo() strsql = "select *...
1
by: drussell10 | last post by:
Using Access 2010: Setup: I have a single table, single form with a combobox that I populate from a single column named "Device Name" in the table. When a user selects a device from the combobox...
7
by: Misbahu | last post by:
Hi guys. I'm wondering if it's possible to do this in MS Access. I'm capturing the login and logout time of employees in my company. I'm currently using 5 forms of Monday through Friday to populate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.