Applecore Pages on Microsoft Access

Changing the Caption of a Form for each Record

If you want to display a caption for the form that will vary according to the record being displayed, then you can put some code in the OnCurrent event for the form itself:

Private Sub Form_Current()
    If Me.NewRecord = True Then
        Me.Caption = "Adding New Record...."
    Else
'   If the field that is being displayed in the caption is numeric and needs to be concatenated with a text string, then use an IsNull check.
        Me.Caption = IIf(IsNull(Me!FieldName), " ", "Data for " & Me!FieldName)
'   If however, it is 2 text strings that are being concatenated, then you can use Nz.
        Me.Caption = Nz("Data for " & Me!FieldName, " ")
    End If
End Sub

In the code above, I first check if the record is new, and then display a caption informing the user that a new record is being added. If this isn't a new record, then display some text in the caption to the user as well as the relevant field. Also, note that instead of using a zero length string ("") if there isn't any data in this field, which will cause the caption to revert to the name of the form, I use a single space (" ").

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 13:54:54