Dependent Form Control

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
On my MS Access Customer form I have a ComboBox called CustomerRequest. An option in the ComboBox is ACCOUNT SUSPENSION. On this same form I have a TextBox called PaymentFrequency with its Visible property set to No. I want the PaymentFrequency Textbox to become visible on the form when the Combox box is equal to ACCOUNT SUSPENSION. I'M new to vba and the code I wrote isn't doing anything.

Private Sub CustomerRequest_AfterUpdate()

If [CustomerRequest] = "ACCOUNT SUSPENSION" Then
[PaymentFrequency].Visible = True
End If

End Sub

Any help greatly appreciated.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Start by putting a break at the start of this code, then switch to the form and update the combo. If the code is firing, it will stop at the break. Mouse over the words CustomerRequest and see what the value is when the help bubble pops up. Alternatively, insert a message box line right after the IF: (msgBox CustomerRequest and it will report the value. If your combo has more than one column, it is likely that the column with the value you're looking to compare isn't the bound column.
 
Upvote 0
I would be using the Me. prefix on your control names.?

Also are you using a table Lookup field for your combo?
 
Upvote 0
I've added the Me.prefix and that does display the PaymentFrequency textbox. However, Once the form is completed and I move on to the next blank form to enter a new record the hidden fields are still visible and will remain that way until I choose another option from the ComboBox. I'm sure this due to the code being fired on the AfterUpdate event. Not sure how to correct. I tried to correct by moving the code to the Form OnLoad event but that didn't work.

Also, For existing records with the ComboBox selection "ACCOUNT SUSPENSION " the hidden field don't display because they are on the AfterUpdate" event.
 
Upvote 0
To control this from record to record, you will need a form Current event also. M$ has lots of info on form events.
 
Upvote 0
OnLoad does what it says on the tin, it runs once when you load the form.?

In forms Current event, you could hide the PaymentFrequency Textbox? if a new record?, if not a new record call the combo afterupdate event?
Or repeat the code in the CurrentEvent. You would also need to hide when not "ACCOUNT SUSPENSION"


Perhaps
Code:
Me.PaymentFrequency.Visible = (Me.CustomerRequest = "ACCOUNT SUSPENSION")
would be more appropriate?

HTH
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top