Populating text box based on value chosen in a combo box

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
140
Office Version
  1. 365
  2. 2019
Good morning,

I am a newbie with Access. I have what I believe is a simple question but seem to be able to find an answer. Either I am using the incorrect word patterns to find a solution or the answer is embedded in something else so i apologize if I have just missed it. A link to the answer would be perfectly acceptable.

I have combo box named PlanYear with years for choices (2019,2020,2021,2022). I have a text box named Filer. What I would like to happen is if 2020 is chosen in the PlanYear I would like the Filer box to show a name.

I have tried variations of the code below and although it runs without error it will not display the name. I have tried several variations of the code below but without success. Any help would be greatly appreciated.

Private Sub GroupName___ID_Exit(Cancel As Integer)
If Me.PlanYear = "2020" Then
Me.Filer = "Joe"
End If

End Sub


Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Rholdren,

It appears that this code is not linked to the Combo Boxe's Change event. It may be that the sub isn't getting called upon such an event.

Try this:

VBA Code:
Private Sub PlanYear_Change()
    With Me
        If .PlanYear = "2020" Then
            .Filer = "Joe"
        End If
    End With
End Sub
 
Upvote 0
Hi Rholdren,

It appears that this code is not linked to the Combo Boxe's Change event. It may be that the sub isn't getting called upon such an event.

Try this:

VBA Code:
Private Sub PlanYear_Change()
    With Me
        If .PlanYear = "2020" Then
            .Filer = "Joe"
        End If
    End With
End Sub
Thanks Richh That was perfect. Very much appreciated.
 
Upvote 0
Probably not an issue for that sub but the usual event used is AfterUpdate when validation is not required. If required then you'd use BeforeUpdate. Change event will fire after update events when a value is chosen, but it will also fire for every keystroke if you type in the control, including backspace. Might want to consider that.
 
Upvote 0
Good point, Micron. I'm use to making listboxes that update upon keystroke in text/combo boxes. My bad.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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