Reset form when adding a new record

D

dwaynesworld

I tried to find a solution to this in the previous threads but was unable to.
I have a form with many areas that are to be filled. I also have a check
box which will hide/disable many of the forms when checked. After a user
completes the form with the checkbox set to true and they elect to enter a
new record, the checkbox value is false but the disabled sections on the form
are still disabled. I have to check then uncheck the box to activate the
disabled sections. Is there a way to have access automatically reset the
disabled sections to be enabled once we add a new record? I have attached
some code below to help:

********************************************************
This code is for the checkbox

Private Sub Prep_Wrap_Hours_Only_AfterUpdate()
If [Prep/Wrap Hours Only].Value = True Then
[Team Asst].Enabled = False
[Counselor].Enabled = False
[Processor].Enabled = False
[Underwriter].Enabled = False
[Closer].Enabled = False
[Other].Enabled = False
[OPM].Enabled = False
[RSM].Enabled = False
[AOM].Enabled = False
[BM].Enabled = False
[PM].Enabled = False
[BQ].Enabled = False
[ISD].Enabled = False
[QC].Enabled = False
[DIST].Enabled = False
[NSD].Enabled = False
[OD].Enabled = False
[CS].Enabled = False
[qrpAudience].Enabled = False
[chkCo-Facilitator].Enabled = False
[Other Comments].Enabled = False
[txtFacilitatorHours].Enabled = False
[txtTotalParticipants].Enabled = False
[grpFacilitatorType].Enabled = False
[Delivery Method].Enabled = False
[eLearning Hours].Enabled = False
[eLearning Hours].Value = 0
Else
[Team Asst].Enabled = True
[Counselor].Enabled = True
[Processor].Enabled = True
[Underwriter].Enabled = True
[Closer].Enabled = True
[Other].Enabled = True
[OPM].Enabled = True
[RSM].Enabled = True
[AOM].Enabled = True
[BM].Enabled = True
[PM].Enabled = True
[BQ].Enabled = True
[ISD].Enabled = True
[QC].Enabled = True
[DIST].Enabled = True
[NSD].Enabled = True
[OD].Enabled = True
[CS].Enabled = True
[qrpAudience].Enabled = True
[chkCo-Facilitator].Enabled = True
[Other Comments].Enabled = True
[txtFacilitatorHours].Enabled = True
[txtTotalParticipants].Enabled = True
[grpFacilitatorType].Enabled = True
[Delivery Method].Enabled = True
[eLearning Hours].Enabled = True
End If

End Sub
*****************************************************
This code is for the command button to add a new record

Private Sub cmdNewCourse_Click()
On Error GoTo Err_cmdNewCourse_Click


DoCmd.GoToRecord , , acNewRec
Me.Instructor.SetFocus

Exit_cmdNewCourse_Click:
Exit Sub

Err_cmdNewCourse_Click:
MsgBox Err.Description
Resume Exit_cmdNewCourse_Click

End Sub

Thanks!!!!!
 
Y

Yanick

I think the solution is simple. Put the code to enable/disable your section
in a new sub (for exemple: private sub ActivateDesactivateControl(Status as
boolean))

Then call this sub with the desired status where you need (After your save
for instance)

Sub should look like this :

private sub ActivateDesactivateControl(Status as boolean)
[Team Asst].Enabled = Status
[Counselor].Enabled = Status
[Processor].Enabled = Status
[Underwriter].Enabled = Status
[Closer].Enabled = Status
[Other].Enabled = Status
[OPM].Enabled = Status
[RSM].Enabled = Status
[AOM].Enabled = Status
[BM].Enabled = Status
[PM].Enabled = Status
[BQ].Enabled = Status
[ISD].Enabled = Status
[QC].Enabled = Status
[DIST].Enabled = Status
[NSD].Enabled = Status
[OD].Enabled = Status
[CS].Enabled = Status
[qrpAudience].Enabled = Status
[chkCo-Facilitator].Enabled = Status
[Other Comments].Enabled = Status
[txtFacilitatorHours].Enabled = Status
[txtTotalParticipants].Enabled = Status
[grpFacilitatorType].Enabled = Status
[Delivery Method].Enabled = Status
[eLearning Hours].Enabled = Status
end sub

It will cut your code by half and you can activate/deactivate your control
from everywhere you need.

To Activate :
call ActivateDesactivateControl(TRUE)

To Deactivate
call ActivateDesactivateControl(FALSE)

--
Yanick


dwaynesworld said:
I tried to find a solution to this in the previous threads but was unable to.
I have a form with many areas that are to be filled. I also have a check
box which will hide/disable many of the forms when checked. After a user
completes the form with the checkbox set to true and they elect to enter a
new record, the checkbox value is false but the disabled sections on the form
are still disabled. I have to check then uncheck the box to activate the
disabled sections. Is there a way to have access automatically reset the
disabled sections to be enabled once we add a new record? I have attached
some code below to help:

********************************************************
This code is for the checkbox

Private Sub Prep_Wrap_Hours_Only_AfterUpdate()
If [Prep/Wrap Hours Only].Value = True Then
[Team Asst].Enabled = False
[Counselor].Enabled = False
[Processor].Enabled = False
[Underwriter].Enabled = False
[Closer].Enabled = False
[Other].Enabled = False
[OPM].Enabled = False
[RSM].Enabled = False
[AOM].Enabled = False
[BM].Enabled = False
[PM].Enabled = False
[BQ].Enabled = False
[ISD].Enabled = False
[QC].Enabled = False
[DIST].Enabled = False
[NSD].Enabled = False
[OD].Enabled = False
[CS].Enabled = False
[qrpAudience].Enabled = False
[chkCo-Facilitator].Enabled = False
[Other Comments].Enabled = False
[txtFacilitatorHours].Enabled = False
[txtTotalParticipants].Enabled = False
[grpFacilitatorType].Enabled = False
[Delivery Method].Enabled = False
[eLearning Hours].Enabled = False
[eLearning Hours].Value = 0
Else
[Team Asst].Enabled = True
[Counselor].Enabled = True
[Processor].Enabled = True
[Underwriter].Enabled = True
[Closer].Enabled = True
[Other].Enabled = True
[OPM].Enabled = True
[RSM].Enabled = True
[AOM].Enabled = True
[BM].Enabled = True
[PM].Enabled = True
[BQ].Enabled = True
[ISD].Enabled = True
[QC].Enabled = True
[DIST].Enabled = True
[NSD].Enabled = True
[OD].Enabled = True
[CS].Enabled = True
[qrpAudience].Enabled = True
[chkCo-Facilitator].Enabled = True
[Other Comments].Enabled = True
[txtFacilitatorHours].Enabled = True
[txtTotalParticipants].Enabled = True
[grpFacilitatorType].Enabled = True
[Delivery Method].Enabled = True
[eLearning Hours].Enabled = True
End If

End Sub
*****************************************************
This code is for the command button to add a new record

Private Sub cmdNewCourse_Click()
On Error GoTo Err_cmdNewCourse_Click


DoCmd.GoToRecord , , acNewRec
Me.Instructor.SetFocus

Exit_cmdNewCourse_Click:
Exit Sub

Err_cmdNewCourse_Click:
MsgBox Err.Description
Resume Exit_cmdNewCourse_Click

End Sub

Thanks!!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top