Regarding code for nulling fields on an Access form

Tiosylanyl

New Member
Joined
Jul 31, 2006
Messages
48
Hello,

I'm working on a user entry form, and I have a field that enables/disables and nulls depending on a response given in a combo box (LOA).

Here is the code that I'm using:
Code:
Private Sub LOA_AfterUpdate()
If Me.LOA = "No" Then
    Me.Start_Date.Enabled = False
    Start_Date = Null
End If
If Me.LOA = "Yes" Then
   Me.Start_Date.Enabled = True
End If
End Sub

This works fine from a user entry standpoint up until I begin to scroll through subsequent records. For instance, if my first record has "No" in the LOA combo box, the Start Date field is null. When I scroll to the next record, if the LOA combo is "Yes" (and therefore a value already entered into the Start Date field), the Start Date field still maintains its value, but it becomes disabled.

I can remedy this by changing the value in the LOA combo box and resetting it, however, I was wondering if anyone out there knows of an addition I can make to the code that would take care of this.

Thanks in advance.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If you place your code in the FORMs On Current event, it will trigger each time you move to another record. When you have the code in the AfterUpdate event, it will trigger ONLY after you update that field. So, when you move to a new record, unless you update LOA, the code won't run a second time.

Also. you could clean up your code a bit.

If me.LOA = "No" then
do something
elseif me.LOA = "Yes" then
do something else
end if

If Yes/No are the only two possiblities, you could use:
If me.LOA = "No" then
do something
else
do something else
end if
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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