?
Solved

Reset Access Form after change to field

Posted on 2009-05-05
4
Medium Priority
?
567 Views
Last Modified: 2013-11-28
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

0
Comment
Question by:Haze0830
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24306906
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
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 24306935

sub resetControls()
me.description.enabled=true
me.comments.enabled=true

etc....

end sub


Private Sub Category_AfterUpdate()
 
On Error GoTo Error_Handler
 
resetControls 'this will reset all the controls


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
0
 
LVL 2

Author Comment

by:Haze0830
ID: 24307955
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!!
0
 
LVL 2

Author Closing Comment

by:Haze0830
ID: 31578114
Thanks again!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question