I have created a form to enter training events. I have an unbound calculated control at the top of my form which reflects the status of the training. Calculated control source:
=IIf(IsNull([Txt_TrainComm]),"NEW",IIf(IsNull([Txt_TrainComp]),"COMMENCED",IIf(IsNull([txtAssNom]),"ASSESSMENT REQUIRED",IIf(IsNull([txtAssComp]),"ASSESSMENT - NOMINATED","ASSESSED"))))
My form has a few key dates (Text Box Names: txt_TrainComm, txt_TrainComp, txtAssNom & txtAssComp) to be entered in that order. What I want to happen is as the dates are entered other form controls are enabled, the footer is made visible etc. I have written a code that when placed in the Form Current Event works fine when switching from one record to the next. Please see my code so far below:
Private Sub Form_Current()
If Me.StatusName = "NEW" Then
Me.StatusName.Width = 1418
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = False
If Me.FormFooter.Visible = True Then
Me.FormFooter.Visible = False
Me.cmdShowdetails__.Caption = "Show Assessment <<"
Dim WindowHeightNEW As Long
WindowHeightNEW = Me.WindowHeight - Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightNEW
End If
End If
If Me.StatusName = "COMMENCED" Then
Me.StatusName.Width = 2552
Me.Txt_TrainComp.Enabled = True
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = False
If Me.FormFooter.Visible = True Then
Me.FormFooter.Visible = False
Me.cmdShowdetails__.Caption = "Show Assessment <<"
Dim WindowHeightCOMM As Long
WindowHeightCOMM = Me.WindowHeight - Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightCOMM
End If
End If
If Me.StatusName = "ASSESSMENT REQUIRED" Then
Me.StatusName.Width = 4253
Me.Txt_TrainComp.Enabled = True
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSREQ As Long
WindowHeightASSREQ = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSREQ
End If
End If'
If Me.StatusName = "ASSESSMENT - NOMINATED" Then
Me.StatusName.Width = 4925
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = False
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSNOM As Long
WindowHeightASSNOM = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSNOM
End If
End If
If Me.StatusName = "ASSESSED" Then
Me.StatusName.Width = 1985
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = False
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSD As Long
WindowHeightASSD = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSD
End If
End If
End Sub
What I cant get to work, is placing the code in the correct control event so that for example, when a date is entered into txt_TrainComp, the code is run dynamically. I have to switch to a different record and then back for the changes to take effect which isn't the desired result. I have tried BeforeUpdate, AfterUpdate, OnDirty, OnChange and they dont seem to work.
Is someone able to please have a look and make a suggestion to what event or code changes I need to make? Hopefully I have provided enough information.
Thank you in advance.
Thanks to RetiredGeek, FormObject_LostFocus() was the correct event to run the code after focus is changed.
Private Sub Txt_TrainComm_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub Txt_TrainComp_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub txtAssComp_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub txtAssNom_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub