On main menu form (MainForm), when user clicks a button it runs the following code, which opens a new form and changes the title(caption)- (displayed in a label in the header section).
Code:
DoCmd.OpenForm "Validate", acNormal
Forms!Validate.Lbl_BannerValidate.Caption = "Edit Data"
When the form opens, I want to check to see what the title is, and depending on the title, perform an action. The form opens and displays the correct title after running the above code ("Edit Data"), however, it is not recognizing the caption value correctly. Even though the caption correctly displays the programmatically altered caption, the below code only recognizes the default caption listed in the label's (Lbl_BannerValidate) property box.
Code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.Close acForm, "MainForm", acSaveNo
If Me!Lbl_BannerValidate.Caption = "Validate Data" Then
If Me!cmdSamples.Visible = "No" Then
Me!cmdSamples.Visible = "Yes"
End If
End If
If Me!Lbl_BannerValidate.Caption = "Edit Data" Then
If Me!cmdSamples.Visible = "Yes" Then
Me!cmdSamples.Visible = "No"
End If
End If
Debug.Print Me!Lbl_BannerValidate.Caption
End Sub
Debug.Print returns the value "Validate Data" instead of "Edit Data".
How can I rewrite my code to recognize the new caption and execute the proper if statements when true?
Access 2007