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! - Option Compare Database
-
-
Private Sub cboClass_AfterUpdate()
-
If Not IsNull(Me![CBOclass]) Then
-
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)));"
-
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
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 : - Option Compare Database
-
Option Explicit
-
-
Private Sub cboClass_AfterUpdate()
-
Call ChangeRowSource()
-
End Sub
-
-
Private Sub cboSize_AfterUpdate()
-
Call ChangeRowSource()
-
End Sub
-
-
Private Sub ChangeRowSource()
-
With Me
-
If Not IsNull(.CBOclass) And Not IsNull(.cboSIZE) Then
-
.txtCommodityNum = DLookup("[COMMODITY_NUM]", _
-
"tblCOMMODITY", _
-
"[CLASS] = '" & .cboClass & "' And " & _
-
"[SIZE] = '" & .cboSize & "'")
-
End If
-
End With
-
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.
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?
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 : - Option Compare Database
-
Option Explicit
-
-
Private Sub cboClass_AfterUpdate()
-
Call ChangeRowSource()
-
End Sub
-
-
Private Sub cboSize_AfterUpdate()
-
Call ChangeRowSource()
-
End Sub
-
-
Private Sub ChangeRowSource()
-
With Me
-
If Not IsNull(.CBOclass) And Not IsNull(.cboSIZE) Then
-
.txtCommodityNum = DLookup("[COMMODITY_NUM]", _
-
"tblCOMMODITY", _
-
"[CLASS] = '" & .cboClass & "' And " & _
-
"[SIZE] = '" & .cboSize & "'")
-
End If
-
End With
-
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.
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!
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 :-)
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
by: Filips Benoit |
last post by:
Dear all,
How can i populate a combo with the field-caption-names of 1 table?
Thanks
Filip
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
|
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...
| |