473,395 Members | 1,456 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,395 software developers and data experts.

How do you make a combo box update a field no matter which order you enter it?

269 256MB
I have found a little trip-up in my otherwise terrific database. When you go on a form to enter order details, you first choose a CLASS and then you choose a SIZE. When doing this in that order, a third combo box automatically populates with the item number (COMMODITY_NUM). If you make an error and change the SIZE, the COMMODITY_NUM will update itself. However, if you made an error to the CLASS and go back to change it after you have already entered a size, the COMMODITY_NUM will not update, and it ends up storing the wrong information. Can someone tell me what to do to my code to fix it?
Thanks in advance!
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub cboClass_AfterUpdate()
  4. If Not IsNull(Me![CBOclass]) Then
  5.   Me![cboSIZE].RowSource = "SELECT [SIZE] FROM tblCOMMODITY WHERE [CLASS] = '" & Me![CBOclass] & "' ORDER BY CInt(IIf(IsNumeric(Right([SIZE],1)),[SIZE],Left([SIZE],Len([SIZE])-1)));"
  6. End If
  7. End Sub
  8.  
  9. Private Sub cboSize_AfterUpdate()
  10. If Not IsNull(Me![CBOclass]) And Not IsNull(Me![cboSIZE]) Then
  11.   Me![txtCommodityNum] = DLookup("[COMMODITY_NUM]", "tblCOMMODITY", "[CLASS] = '" & Me![CBOclass] & _
  12.                        "' And [SIZE] = '" & Me![cboSIZE] & "'")
  13. End If
  14. End Sub
Mar 21 '11 #1

✓ answered by NeoPa

Danica:
Ok NeoPa, I think I get what you are saying. I need to remove the DLOOKUP function and build some altogether new code, right?
Not really. The code should be the same for both. The code should handle both fully. The format of your code should be something like the following :

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cboClass_AfterUpdate()
  5.     Call ChangeRowSource()
  6. End Sub
  7.  
  8. Private Sub cboSize_AfterUpdate()
  9.     Call ChangeRowSource()
  10. End Sub
  11.  
  12. Private Sub ChangeRowSource()
  13.     With Me
  14.         If Not IsNull(.CBOclass) And Not IsNull(.cboSIZE) Then
  15.             .txtCommodityNum = DLookup("[COMMODITY_NUM]", _
  16.                                        "tblCOMMODITY", _
  17.                                        "[CLASS] = '" & .cboClass & "' And " & _
  18.                                        "[SIZE] = '" & .cboSize & "'")
  19.         End If
  20.     End With
  21. End Sub
This code is mainly guesswork, but the format is important. Notice how both event procedures call the common procedure where all the actual work is done. Notice also the Option Explicit line (#2). This is important (See Require Variable Declaration).

PS. The name of the procedure may be a bit wrong for the code, but I couldn't tell what was what when I set it up.

7 1432
NeoPa
32,556 Expert Mod 16PB
The approach to take when dealing with multiple controls that effect filtering, or any other response really, is to design a function to do the work generally. This function is then called when any of the determining controls is changed. Clearly the function would be built to handle all the data it needs (not just the most recently changed control) so it should work correctly whichever order the controls are updated.
Mar 21 '11 #2
DanicaDear
269 256MB
Ok NeoPa, I think I get what you are saying. I need to remove the DLOOKUP function and build some altogether new code, right? Or could I just add another DLOOKUP to the first sub, perhaps using an IF statement to say IF a size has been chosen, then DLOOKUP my COMMODITY_NUM?
Mar 21 '11 #3
NeoPa
32,556 Expert Mod 16PB
Danica:
Ok NeoPa, I think I get what you are saying. I need to remove the DLOOKUP function and build some altogether new code, right?
Not really. The code should be the same for both. The code should handle both fully. The format of your code should be something like the following :

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cboClass_AfterUpdate()
  5.     Call ChangeRowSource()
  6. End Sub
  7.  
  8. Private Sub cboSize_AfterUpdate()
  9.     Call ChangeRowSource()
  10. End Sub
  11.  
  12. Private Sub ChangeRowSource()
  13.     With Me
  14.         If Not IsNull(.CBOclass) And Not IsNull(.cboSIZE) Then
  15.             .txtCommodityNum = DLookup("[COMMODITY_NUM]", _
  16.                                        "tblCOMMODITY", _
  17.                                        "[CLASS] = '" & .cboClass & "' And " & _
  18.                                        "[SIZE] = '" & .cboSize & "'")
  19.         End If
  20.     End With
  21. End Sub
This code is mainly guesswork, but the format is important. Notice how both event procedures call the common procedure where all the actual work is done. Notice also the Option Explicit line (#2). This is important (See Require Variable Declaration).

PS. The name of the procedure may be a bit wrong for the code, but I couldn't tell what was what when I set it up.
Mar 21 '11 #4
DanicaDear
269 256MB
Yes, that did it. I guess you can tell I have launched my DB and am now finding just really small things that I didn't notice before. Everyone has been really pleased with my project so far, though. (especially me!!)

Thanks so much for ALL your help. I could have never been successful without Bytes and it's experts!
Mar 22 '11 #5
NeoPa
32,556 Expert Mod 16PB
I'm really pleased to hear it Danica. You deserve some approbation for your approach to it. You've always tried to get it as right as possible and never shied away from some complicated new approaches. Good for you :-)
Mar 22 '11 #6
DanicaDear
269 256MB
Last year I got a $500 bonus for my efforts! :-) It was very flattering! (Then I thought to myself, I should send a portion of this to NeoPa.) LOL.
Mar 22 '11 #7
NeoPa
32,556 Expert Mod 16PB
I'll send you my details :-D

Good for you though. I'm really pleased for you. That's always nice. When you're appreciated.

PS. Next time you're in London you can buy me a pint.
Mar 22 '11 #8

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

Similar topics

3
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
1
by: Kelly Olsen | last post by:
I have created an automatic update field in my Vendor_Table that automatically updates the date in that field to respond to any changes made to the record. However, I would like to display this...
1
by: Andy Frank | last post by:
I have a tabular form that has a combo box on it that is reading from a database. When that combobox changes, I want it to lookup a database record to get a value and set the value into another...
5
by: Filips Benoit | last post by:
Dear all, How can i populate a combo with the field-caption-names of 1 table? Thanks Filip
1
by: | last post by:
Greets, I have a question I have combo box that gets a column in a dataset when I change the combo box the dataset changes and that works well. The problem is the fields on the from that...
1
by: ainsley | last post by:
Hi this is going to sound like a very basic question, but I am creating a database in Access which is based on a number of unlimited tables. In my data entry form i have a number of combo boxes...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
0
by: srinivasarao yarru | last post by:
hi sir, in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse...
6
by: KevinPreston | last post by:
Hello everyone, this is my first post so apologies if i dont get it right first time, i am a self taught Access user, i am stuck on something i am trying to do, briefly i have 2 tables, one for...
5
by: Samc | last post by:
This may be abit basic, I am a self taught Access user. I have a form in my database to add soldiers details and they are assigned a cohort number depending on when they enlisted. For example if they...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.