Solved

Reset Access Form after change to field

Posted on 2009-05-05
4
539 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
  • 2
  • 2
4 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero earned 500 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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now