Solved

Reset Access Form after change to field

Posted on 2009-05-05
4
558 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 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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