Dealing with electric utility rubber gloves.....
tblCOMMODITY contains fields CLASS, SIZE, & COMMODITY_NUM (PK). A class combined with a size make a commodity number. I don't want the user selecting gloves by commodity number because they are 7 digit numbers that make no literal sense. DB users will select what a customer needs by two combo boxes, first by class, then by size.
Question 1. Class 3 only has 4 sizes available. Class 2 has 8 sizes available. I'd really like to have my second combo box values be dependent on what is selected in the first combo box, so that they don't make combinations that aren't available. How do I do it? A recent post posed a similar question: http://bytes.com/topic/visual-basic-...-box-selection but the link provided was more than I could comprehend. Can anyone offer another approach?
Question 2. When the two combo box selections are made, I'd like to automatically pull in the COMMODITY_NUM, which is the PK. Can I handle that with dlookup or something similar?
Thanks so much!
27 3907
You add an AfterUpdate event handler to the first combobox, - Private Sub cmb_Class_AfterUpdate()
-
cmb_Size.Requery
-
End Sub
You then make the 2nd combobox query include the first combobox as a selection criteria, which would look something like this: - Forms!Frm_Order!cmb_Class
To store the Primary key you should always have your combobox query contain the primary Key, and simply hide it.
You do this by setting the Number of columns in the combobox's properties, and by setting the first column width's to 0. That way you display the user friendly value, but store the primary key.
ADezii 8,834
Recognized Expert Expert
Hello Danica. I've created a Simple Demo that should point you in the right direction, just Download it.
TheSmileyOne and ADezii,
Thank you SO MUCH for your replies! When I read Smiley's reply I knew I was still not out of the woods because I don't yet know what a Combobox query is. However I figured with some research I could get closer to my answer. ADezii, you always go the extra step for me and I feel so undeserving. You people are SO NICE and just when I think my software writing is a lost cause someone steps up and keeps me rolling. I cannot say enough nice words for your support and encouragement (and expertise!). :-) I will be away from work for the next week so it will be until then that I get all this worked out and report my success! Thanks so much until then....
Danica
PS. ADezii, your program demonstrates exactly what I was trying to do. I will investigate it thoroughly and also reply to another post so I can help out someone else trying to do something similar. ;-)
ADezii 8,834
Recognized Expert Expert
The pleasure is all ours, DanicaDear.
ADezii,
I finally got the class combobox working (it only took 5 hours, lol) and after much, much research, I have to say I'm sort of stuck again.
First, I've checked every box and label that I know possible and I have my DB set up just like yours as far as I can tell. The only difference, which I'm thinking may be a big one, is you use number data type in your table where I used text. I used text because some of the sizes have an "L" behind them (size 10L). I read in a book that unless numbers represent a quantity, to use text as the datatype, and that's what I did. I think this is a problem (it might be the only problem) because I get this error when trying to punch data into my form: "Data type mismatch in criteria expression" Upon further research, I am wondering if the problem lies in my code, which is used to compare or select based on numeric matches rather than text matches? Unfortunately, I'm not slick enough to correct it, although I will admit I have tried. :-(
I now have some understanding of how this is working...we are really just using the (hidden) commodity number, or column 1, to select things. This has been what I have learned from this exercise. At first I thought my error was somewhere in this area so I have researched and tried different things. Came out knowing lots more, but with a problem I still can't fix.
Here is the code from your DB that I am trying to use, just as a time saver. Can you comment on how it might change if my datatypes are text rather that number? - Private Sub cboClass_AfterUpdate()
-
If Not IsNull(Me![cboCLASS]) Then
-
Me![cboSIZE].RowSource = "SELECT [SIZE] FROM tblCOMMODITY
-
WHERE [CLASS] = " & Me![cboCLASS]
-
End If
-
End Sub
-
-
Private Sub cboSize_AfterUpdate()
-
If Not IsNull(Me![cboCLASS]) And Not IsNull(Me![cboSIZE]) Then
-
Me![txtCommodityNum] = DLookup("[COMMODITY_NUM]", "tblCOMMODITY",
-
"[CLASS] = " & Me![cboCLASS] & " And [SIZE] = " & Me![cboSIZE])
-
End If
-
End Sub
Thanks!!! Danica
If your using strings, you have to inform access of that. The way you do that is in criteria expressions such as the one mentioned: - "[CLASS] = " & Me![cboCLASS] & ""
is to add ' at the beginning and end of string literal.
Example: - "[CLASS] = '" & Me![cboCLASS] & "'"
Well well well, what do you know...IT'S WORKING! (almost)
This has definetely solved my biggest problem, and I said if you guys said it had something to do with those quote marks I was having a party tonight! Woohoo!
So I have the size matched up with the class...but it's not pulling in my commodity number. I know it's more quote marks but I've tried different combinations and my guesses aren't working. Can you help me once more?
This is the line where I think the problem is: -
Me![txtCommodityNum] = DLookup("[COMMODITY_NUM]", "tblCOMMODITY",
-
"[CLASS] = " & Me![cboCLASS] & " And [SIZE] = " & Me![cboSIZE])
-
When I choose the class and size combination, I get a Visual Basic run-time error: Data type mismatch in criteria expression
I don't know after what the & " ' " is required. Please excuse my ignorance but I just don't know how it works. This code is not "English" and that's the only language I speak. LOL.
ADezii 8,834
Recognized Expert Expert - Me![txtCommodityNum] = DLookup("[COMMODITY_NUM]", "tblCOMMODITY", "[CLASS] = '" & Me![cboCLASS] & _
-
"' And [SIZE] = '" & Me![cboSIZE] & "'")
OMG....you people are A-W-E-S-O-M-E! And just think, it's 10 minutes til 5 so I can close this out before the weekend (and therefore have a nice one...I tend to overworry about my programming, lol).
Actually, ADezii, I *thought* I had tried the combination before I replied back with that problem but I guess I missed something.
Thanks to you all!!!!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mr_burns |
last post by:
hi,
is it possible to change the contents of a combo box when the contents
of another are changed. for example, if i had a combo box called
garments containing shirts, trousers and hats, when the user selects
shirts another combo box called 'size' would contain sizes in relation
to shirts (ie. chest/neck size). the same would occur for trousers and
hats. when the user selects an option in the garment combo box, the
options available...
|
by: Maria Joao |
last post by:
I have two synchronized combo boxes and after the selection of the
desired record, I need the user to open the related report, by
pressing a button.
My problem is that a combo box doesn't update do the first one. The
record are correct, but the first one is always from the last
selection. How can I update the second combo box?
Thanks
|
by: BigJay |
last post by:
I am 1. trying to have a combobox used as a selector to display records
in a subform. and not sure on how to get selected info into subform.the
combo is populated but can not get subform updated when selection is
made.....
2. I also want to use one combo box to select a second set of
criteria in a second combo box that is then used to refine displayrd
records in a a subform.... am afraid im lost on this..???
I have a main table that...
|
by: jjyconsulting |
last post by:
Newbie needing some help. I have a tblParticipants. The fields
include gender, education_level, income, occupation etc., I'm trying to
create a form where a user can run a query from the form and just
choose the appropriate criterias from the combo boxes to get the
results. I also want the query to run even if there is not a value in
all the combo boxes ie., i want just all males with income level of
over $100,000...Any insights or help...
|
by: Torilyn73 |
last post by:
I posted this earlier... or thought I did... anyway.. it's doesn't
appear in the list so I'm reposting it.
Can someone please explain to me how to set up the lostfocus event
for a combo box. I need the combo to return to its default value when
the user clicks away from it ... either somewhere on the form itself
or another app. I have no clue how to do this and would really
appreciate some help.
Thanks!
| |
by: GaryGreenberg |
last post by:
I am developing a web page for order processing using Spring MVC.
In my JSP I have a table populated from the list of orders that are passed in the model (form backing object). Some fields there are filled and some are not.
User is suppose to complete mandatory fields and submit the form further.
I have it almost done except one thing where I can use some help.
One <td> contains 2 related combo boxes for shipping service selection:
First...
|
by: bloukopkoggelmander |
last post by:
Hi all
Now this seems staright forward, but I am having loads of problems getting this to work.
What I want to do is to have two combo boxes . The user makes a selection in the top one and then only data relavant to the selection is then displayed in the combo box below where the user can make another choise.
For instance :
I have one table - VehicleMakeAndModel
|
by: didihynes |
last post by:
Hi Guys,
I'm in desparate need of help. I am producing a database for my dissertation and have got majorly stuck. I am currently creating a form in which the user will select a student from a combo box, which that selection populates the next combo for the course selection. I have managed to do that with the coding shown below, my next combo will work from the course selection to bring back the feedback topics associated with that course,...
|
by: kcdoell |
last post by:
I have 5 cascading combo boxes on a form. Below is a sample of my vb in the first combo box:
Private Sub CboDivision_AfterUpdate()
'When the Division is selected, the appropriate Segment list will
'display in the drop down list of CboSegment
With Me!
If IsNull(Me!cboDivision) Then
|
by: dudeja.rajat |
last post by:
On Sat, Aug 30, 2008 at 2:32 PM, Fredrik Lundh <fredrik@pythonware.comwrote:
Fredrik, Thanks so much. That worked.
Following this, I can now see that my combo2 has no previous elements
and contains only the elements relevant to selection in combo1.
Now, as soon as I select something in combo 2 and go back to change
selection in combo1 the combo2 must get its history cleared up (i.e
the previous selection in combo2's entry subwidget)
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |