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

Update a combo box after changing another combo box

Greetings,

I have an Access 2002 continuous form called "Project Update Form" in which users can update project values presented in a series of combo boxes and text boxes. I have three combo boxes ("FY", "Qtr" and "Mth") that contain the values for a project's deadline: fiscal year, quarter and month, respectively.

My goal is to build an AfterUpdate event procedure such that when a user changes a value for any of the three aforementioned combo boxes, an automatic change will occur to the value in a fourth combo box (named "Status"), changing its value to a pre-determined setting (in this case, "Yellow"), which is sourced from a query ("QryUniqueStatus").

Whatever help you can offer would be most appreciated.

Regards,

- JM
Feb 12 '08 #1
8 11957
puppydogbuddy
1,923 Expert 1GB
Greetings,

I have an Access 2002 continuous form called "Project Update Form" in which users can update project values presented in a series of combo boxes and text boxes. I have three combo boxes ("FY", "Qtr" and "Mth") that contain the values for a project's deadline: fiscal year, quarter and month, respectively.

My goal is to build an AfterUpdate event procedure such that when a user changes a value for any of the three aforementioned combo boxes, an automatic change will occur to the value in a fourth combo box (named "Status"), changing its value to a pre-determined setting (in this case, "Yellow"), which is sourced from a query ("QryUniqueStatus").

Whatever help you can offer would be most appreciated.

Regards,

- JM
One thing is not clear....Do you want the background color in Status to change to yellow or do you want the Status to say "Yellow"? In any event, the easiest way to accomplish what you want would be to enclose the 3 combo boxes in an option group frame from Access's toolbox. Once you do that, you will be able to code for a change in any of the 3 comboboxes in the AfterUpdate of the option group. If you need further assistance with the code,post back.
Feb 13 '08 #2
One thing is not clear....Do you want the background color in Status to change to yellow or do you want the Status to say "Yellow"? In any event, the easiest way to accomplish what you want would be to enclose the 3 combo boxes in an option group frame from Access's toolbox. Once you do that, you will be able to code for a change in any of the 3 comboboxes in the AfterUpdate of the option group. If you need further assistance with the code,post back.

I enclosed the 3 combo boxes in an option group frame but could use your assistance with the AfterUpdate code.

Thanks,

- JM

P.S. I want the Status to change to the value "Yellow" (not the color).
Feb 13 '08 #3
KingKen
68
I too would love to see this code since i am doing the same with aome combo boxes of mine. By the way this forum is the best... Thanks guys for the hard work you put in.
Feb 13 '08 #4
puppydogbuddy
1,923 Expert 1GB
Ok, let's get started with code, The code has to be improvised because (as you know) comboboxes are not one of the default options provided by the option group frame. So, if you've taken the first step of placing an option group frame around your 3 comboboxes, you had to select either option buttons, checkboxes, or toggle buttons. So at this point you should have a buttons or checkbox next to each of your comboboxes. Here is the steps you need to take to simulate the option buttons with your comboboxes.
1. Delete all of the buttons or checkboxes, and their labels.....you won't be needing them.
2. Let's assume that the option group frame is named optGrpProject and the comboboxes are named cbo1, cbo2, and cbo3.
3. code onGotFocus events for each of the comboboxes, assigning a value that is passed on to the option group. Note that the AfterUpdate event for the option group is called after the option group value has been assigned. The AfterUpdate has to be called because it does not fire if the update is made via code instead of via data input.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cbo1_GotFocus()
  2.      Me.optGrpProject.Value = 1
  3.      optGrpProject_AfterUpdate
  4. End Sub
  5.  
  6. Private Sub cbo2_GotFocus()
  7.      Me.optGrpProject.Value = 2
  8.      optGrpProject_AfterUpdate
  9. End Sub
  10.  
  11. Private Sub cbo3_GotFocus()
  12.      Me.optGrpProject.Value = 3
  13.      optGrpProject_AfterUpdate
  14. End Sub
  15.  
  16. 4. Code the AfterUpdate event of the option group.  After this has been coded and tested, let me know any refinements you want to make.
  17.  
  18. Private Sub optgrpProject_AfterUpdate()
  19. ' capture the option group value selected and proceed accordingly
  20.  
  21. On Error GoTo Error_Routine
  22.  
  23.     Select Case Me.optgrpProject.Value
  24.         Case 1                                 'status is yellow
  25.              Me!cboStatus = "Yellow"              
  26.         Case 2                                 'status is blue
  27.              Me!cboStatus = "Blue"
  28.         Case 3                                 'status is green
  29.              Me!cboStatus = "Green"
  30.     End Select
  31.  
  32.  
  33. Exit_Continue:
  34.     Exit Sub
  35.  
  36. Error_Routine:
  37.     MsgBox "Error# " & Err.Number & " " & Err.Description
  38.     Resume Exit_Continue
  39.  
  40. End Sub
Feb 13 '08 #5
Ok, let's get started with code, The code has to be improvised because (as you know) comboboxes are not one of the default options provided by the option group frame. So, if you've taken the first step of placing an option group frame around your 3 comboboxes, you had to select either option buttons, checkboxes, or toggle buttons. So at this point you should have a buttons or checkbox next to each of your comboboxes. Here is the steps you need to take to simulate the option buttons with your comboboxes.
1. Delete all of the buttons or checkboxes, and their labels.....you won't be needing them.
2. Let's assume that the option group frame is named optGrpProject and the comboboxes are named cbo1, cbo2, and cbo3.
3. code onGotFocus events for each of the comboboxes, assigning a value that is passed on to the option group. Note that the AfterUpdate event for the option group is called after the option group value has been assigned. The AfterUpdate has to be called because it does not fire if the update is made via code instead of via data input.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cbo1_GotFocus()
  2.      Me.optGrpProject.Value = 1
  3.      optGrpProject_AfterUpdate
  4. End Sub
  5.  
  6. Private Sub cbo2_GotFocus()
  7.      Me.optGrpProject.Value = 2
  8.      optGrpProject_AfterUpdate
  9. End Sub
  10.  
  11. Private Sub cbo3_GotFocus()
  12.      Me.optGrpProject.Value = 3
  13.      optGrpProject_AfterUpdate
  14. End Sub
  15.  
  16. 4. Code the AfterUpdate event of the option group.  After this has been coded and tested, let me know any refinements you want to make.
  17.  
  18. Private Sub optgrpProject_AfterUpdate()
  19. ' capture the option group value selected and proceed accordingly
  20.  
  21. On Error GoTo Error_Routine
  22.  
  23.     Select Case Me.optgrpProject.Value
  24.         Case 1                                 'status is yellow
  25.              Me!cboStatus = "Yellow"              
  26.         Case 2                                 'status is blue
  27.              Me!cboStatus = "Blue"
  28.         Case 3                                 'status is green
  29.              Me!cboStatus = "Green"
  30.     End Select
  31.  
  32.  
  33. Exit_Continue:
  34.     Exit Sub
  35.  
  36. Error_Routine:
  37.     MsgBox "Error# " & Err.Number & " " & Err.Description
  38.     Resume Exit_Continue
  39.  
  40. End Sub

That did the trick! I made one small adjustment: I changed the event procedure from 'GotFocus()' to 'Change()' as I want the AfterUpdate procedure to occur on a change to the date fields.

One more question, if I may: I want to lock the value in cboStatus following the AfterUpdate procedure. This is because I don't want someone to go back and change the status after a date change.

For each of your three cases above, I added a line of code following the Me!cboStatus = " " to read like this, for example:

Select Case Me.optGrpProject.Value
Case 1 'status changes to YELLOW
Me!cboStatus = "YELLOW"
Me!cboStatus.Locked

But when I execute the code I get the following Access error message:

Error #438: Object doesn't support this property or method.

I'm working in Access 2002. Is there another way to code the procedure to lock this field's value?

Thanks a bunch for your help!!
Feb 14 '08 #6
puppydogbuddy
1,923 Expert 1GB
That did the trick! I made one small adjustment: I changed the event procedure from 'GotFocus()' to 'Change()' as I want the AfterUpdate procedure to occur on a change to the date fields.

One more question, if I may: I want to lock the value in cboStatus following the AfterUpdate procedure. This is because I don't want someone to go back and change the status after a date change.

For each of your three cases above, I added a line of code following the Me!cboStatus = " " to read like this, for example:

Select Case Me.optGrpProject.Value
Case 1 'status changes to YELLOW
Me!cboStatus = "YELLOW"
Me!cboStatus.Locked

But when I execute the code I get the following Access error message:

Error #438: Object doesn't support this property or method.

I'm working in Access 2002. Is there another way to code the procedure to lock this field's value?

Thanks a bunch for your help!!

Hmm....the combobox has a locked property, so the error is probably occuring the following reason:

You have a syntax error.
change: Me!cboStatus.Locked to: Me!cboStatus.Locked = True
Feb 14 '08 #7
Hmm....the combobox has a locked property, so the error is probably occuring the following reason:

You have a syntax error.
change: Me!cboStatus.Locked to: Me!cboStatus.Locked = True
Thanks! That worked, but I forgot to mention that I wanted the value locked only for the specific record where the date changed. In other words, if I have 10 records in my table but only 1 whose date changed, I want the cboStatus to be locked for the one record only. Is that possible?

Sorry for the omission. You've been extremely helpful!

- JM
Feb 14 '08 #8
puppydogbuddy
1,923 Expert 1GB
Thanks! That worked, but I forgot to mention that I wanted the value locked only for the specific record where the date changed. In other words, if I have 10 records in my table but only 1 whose date changed, I want the cboStatus to be locked for the one record only. Is that possible?

Sorry for the omission. You've been extremely helpful!

- JM
Off the top of my head, I can't think of a way that you can lock just a control on a specifc record or subset of records ,,,,you would have to lock the entire record or records. If locking the entire record is not a problem, and the cboStatus combobox identifies the record or records to be locked, then you might be able to use Allen Browne's suggestion in the following link regarding the use of a textbox.

http://www.thescripts.com/forum/thread215953.html

Let me know what happens.
Feb 14 '08 #9

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

Similar topics

18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
3
by: dixie | last post by:
I have a form full of subforms which bring summary information onto the form from about 12 different tables. I am trying to get all of that summary information (mainly numbers) into 1 large table...
1
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...
7
by: Arnold | last post by:
Greetings Gurus, In a mainform's header, I have a combobox named comboStudents. The rowsource for this combobox is: SELECT -999 As StudentID, "<Add New Student>" As FullName, "aaa" As...
5
by: keri | last post by:
Hi, I am struggling to learn access and VBA whilst creating a db, progress is slow! So far I have managed to run cascading combo boxes on a form by using a sub in the after update procedure of...
3
by: sparks | last post by:
I have a combo box that when you go to the next combo box it is filtered based on the value in the previous one. so if combo box 1 has fred as its value then combo box 2 has 1 2 3 for values....
4
by: tasmontique | last post by:
Hello everyone, I keep getting a syntax error in my update statement. The only thing that I notice is that although the columns in my table have the same name as the fields on the form the...
4
by: Swinky | last post by:
I am trying to make a combo box dependent on a text box. I cannot get the combo box to pull the related data from the text box. I have been all over this user group & have tried several versions...
4
by: injanib via AccessMonster.com | last post by:
I have a combo box called "Recipient" who's row source is a table called "Main" with three columns. The three columns are "Name", "Floor", "Location". Following the combo box are two fields called...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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

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.