By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Auto updating form fields

P: 16
Hi

I have two drop down boxes in a form both looking at the same table.
When I select info for the 1st box I want the second box to update with the same information. The code I currently have is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Ctl1_Person_Responsible_AfterUpdate()
  2. If "Ctl1_Person_Responsible" = 0 Then
  3. Ctl2_Person_Responsible.Enabled = 0
  4. End If
  5. End Sub

This isn't working. Am I right in the 0 being the first row of data, 1 being the second row etc?

Any help as to where I am going wrong would be great!

Thanks
May 13 '10 #1

✓ answered by gershwyn

@jolaunt
If all you want to do is set the second control to the value of the first, try:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Ctl1_Person_Responsible_AfterUpdate()
  2. Ctl2_Person_Responsible = Ctl1_Person_Responsible
  3. End Sub
This will copy whatever value is in the first control to the second whenever the first is changed.

As far as the code you posted, there a couple things wrong with it. First of all, you don't want quotes around your control name. What you are actually doing is comparing the string literal "Ctl1_Person_Responsible" to the number 0, which will never be true, and the rest of your code will never execute. Even if it did, you are then setting the enabled property of your control to zero, which will disable it.

Share this Question
Share on Google+
2 Replies


100+
P: 122
@jolaunt
If all you want to do is set the second control to the value of the first, try:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Ctl1_Person_Responsible_AfterUpdate()
  2. Ctl2_Person_Responsible = Ctl1_Person_Responsible
  3. End Sub
This will copy whatever value is in the first control to the second whenever the first is changed.

As far as the code you posted, there a couple things wrong with it. First of all, you don't want quotes around your control name. What you are actually doing is comparing the string literal "Ctl1_Person_Responsible" to the number 0, which will never be true, and the rest of your code will never execute. Even if it did, you are then setting the enabled property of your control to zero, which will disable it.
May 13 '10 #2

P: 16
I was over complicating it!

This has worked perfectly.

Thank you
May 13 '10 #3

Post your reply

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