Table set up that feed the comboboxes:
SAPFinishedPartNo
OldPartNo
SAPCompNo
OldCompNo
Combobox Name on form:
1st combobox:cboSAPNNo
2nd Combobox: cboComp - Private Sub cboSAPNNoID_AfterUpdate()
-
-
With Me![cboComp]
-
If IsNull(Me!cboSAPNNo) Then
-
.RowSource = ""
-
Else
-
.RowSource = "SELECT [SAPCompNo] " & _
-
"FROM tblPartNoList " & _
-
"WHERE [SAPFinishedPartNo]=" & Me!SAPCompNo
-
End If
-
Call .Requery
-
End With
-
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....
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: - .RowSource = _
-
"SELECT [SAPCompNo] " & _
-
"FROM tblPartNoList " & _
-
"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 : - .RowSource = "SELECT [SAPCompNo] " _
-
& "FROM [tblPartNoList] " _
-
& "WHERE ([SAPFinishedPartNo]='" & Me.cboSAPNNoID & "')"
See how that works in place of lines #7 through #9.
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 - Private Sub cboSAPNNo_AfterUpdate()
-
-
With Me![cboComp]
-
If IsNull(Me!cboSAPNNo) Then
-
.RowSource = ""
-
Else
-
.RowSource = "SELECT [SAPCompNo] " & _
-
"FROM tblPartNoList " & _
-
"WHERE [SAPFinishedPartNo]=" & Me!cboSAPNNo
-
End If
-
Call .Requery
-
End With
-
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"
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: - Private Sub cboSAPNNo_AfterUpdate()
-
-
With Me![cboComp]
-
-
If IsNull(Me!cboSAPNNo) Then
-
-
.RowSource = ""
-
-
Else
-
-
.RowSource = "SELECT [SAPCompNo]" & _
-
"FROM tblPartNoList " & _
-
"Where [SAPFinishedPartNo]=""[cboSAPNNo]"" "
-
End If
-
-
Call .Requery
-
-
End With
-
-
End Sub
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 ;-)
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. - Private Sub cboSAPNNo_AfterUpdate()
-
-
With Me![cboComp]
-
-
If IsNull(Me!cboSAPNNo) Then
-
-
.RowSource = ""
-
-
Else
-
-
.RowSource = "SELECT [SAPCompNo]" & _
-
"FROM tblPartNoList " & _
-
"Where [SAPFinishedPartNo]=""[cboSAPNNo]"" "
-
End If
-
-
Call .Requery
-
-
End With
-
-
End Sub
NeoPa,
Just noticed I entered it wrong from what you put, but now I get a syntax error when compiling. - .RowSource = "SELECT [SAPCompNo]" & _
-
"FROM tblPartNoList " & _
-
* "WHERE ([SAPFinishedPartNo]='" & Me.cboSAPNNo & "')"
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: - .RowSource = _
-
"SELECT [SAPCompNo] " & _
-
"FROM tblPartNoList " & _
-
"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!
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: - "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.
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.
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...
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....
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.
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.
NeoPa,
We got the filter working perfectly, but for some reason when it is filter the second column isn't present.
Your SQL is only asking for one column.
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.
Glad we could hepp!
Merry Christmas and Happy New Year to you as well!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
by: Moorthi chinna |
last post by:
how to reload combobox in datagridview based on combobox selection in datagridview?
|
by: Poongs |
last post by:
hi
<select name="jobCode" class=comboBox id="jobCode">
<?php
$jobCodeQuery="select * from jobcodecreation";
$jobcodeResult = mysql_query($jobCodeQuery);
echo "<option...
|
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 *...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |