Mike H
Mike H

Reputation: 3

Set a sub-form hidden field to visible, based on a check box status

C, Thank you for your input and encouragement! I have changed my form and script slightly, I am afraid I kept the if then statement as I am comfortable with the formatting. The script now works when the 'On Open'event runs.

Private Sub Form_Open(Cancel As Integer)
Me.ChkAlbumNotes.SetFocus

If Me.ChkAlbumNotes.Value = False Then
    Me.lblAlbumNotes.Visible = False
    Me.txtAlbumNotes.Visible = False
    Me.btnAlbumNotes.Visible = True
Else
    Me.lblAlbumNotes.Visible = True
    Me.txtAlbumNotes.Visible = True
    Me.btnAlbumNotes.Visible = False
End If
Me.TrackName.SetFocus
If Me.TrackName = " " Then
    Me.btnAddRecord.SetFocus
Else
Me.btnNextRecord.SetFocus
End If
End Sub

This is fine when the form opens for the first time but I have a set of navigation buttons that are installed by the application as Macros. I cannot add my script to the On_Click event when the button is clicked, as On_Click is linked to the Macro. Is there a way to incorporate the script from the On_Load process to the pre-defined macro? Or can you suggest a neater way to achieve my requirements which are;

  1. When the form opens,a check is made for the existence of a false value in the checkbox if the check box is set to false, then the Notes Text Box and label are hidden and the notes button is visible.

  2. If the check box has a true value, then the Notes text box and label are made visible and the button is hidden.

  3. On completion of the test I check the field Track Name if this is empty, I assume I am at the last record and give the Add New Record button the focus

  4. If Track Name is not empty, then focus is set to Next Record button

when this button is clicked, the next record page opens and the process starts again.

Many Thanks

Mike

Upvotes: 0

Views: 1271

Answers (1)

ComputerVersteher
ComputerVersteher

Reputation: 2696

You should use the Form_Current event instead of Form_Open . This fires on starting the form (2 times) and everytime you move to another record.

Private Sub Form_Current()
Me.lblAlbumNotes.Visible = Me.ChkAlbumNotes.Value
Me.txtAlbumNotes.Visible = Me.ChkAlbumNotes.Value
Me.btnAlbumNotes.Visible = Not Me.ChkAlbumNotes.Value

If Me.TrackName = "" Then ' I suggest If Me.TrackName = " " being a typo and you want to check if empty ( that's why you should use vbNullString instead of "")
  Me.btnAddRecord.SetFocus
Else
  Me.btnNextRecord.SetFocus
End If
End Sub

Upvotes: 1

Related Questions