Link to home
Start Free TrialLog in
Avatar of Brian
BrianFlag for United States of America

asked on

Reset Access Form after change to field

I have a form with all data entry fields set to disabled. The form is used to enter issues and data associated with 3 different issue types. I have a combo box that allows the user to select the issue type they are entering. I have the code below that enables and highlights required fields for the selected issue types. The code works fine with one exception - if the user mistakenly selects the wrong issue type, when they go back and select the proper type the fields that were previously enabled and highlighted remain as such.

I would like to make it so that if the user selects the wrong issue type and then changes it, all the fields are set to their original state and then the appropriate fields are enabled and highlighted based on the corrected selection.

Essentially:
Wrong selection made - fields for that selection enabled\highlighted.
Correct selection made - irrelevant fields locked\highlight removed, appropriate fields enabled\highlighted.

Or is it just easier to reload the form and make the proper selections from that point? I have a few required fields so I would like to suppress prompting in that case. I can't seem to get this method to work either.

Thanks!
Private Sub Category_AfterUpdate()
 
On Error GoTo Error_Handler
 
Me.Category.SetFocus
If Me.Category.Text = "Product Hold" Then
    Me.Description.BorderColor = RGB(0, 255, 0)
    Me.Description.Enabled = True
End If
If Me.Category.Text = "PCAR" Then
    Me.Comments.BorderColor = RGB(0, 255, 0)
    Me.Comments.Enabled = True
End If
Exit Sub
 
Error_Handler:
   MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number
   Exit Sub
   
End Sub

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

create a sub the set all the controls to enable and other properties to default

then call the sub first in the afterupdate event of the combo before setting the other controls to the desired setting
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brian

ASKER

that was incredibly simple and effective. I only changed one portion - instead of enabled I set it to disabled as I want all the fields to be locked by default.

Thanks!!
Avatar of Brian

ASKER

Thanks again!