Dynamic Form Caption

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I need help in changing the caption on my form depending on the form's use:
adding a record, updating a record, or deleting a record. My code is as
follows:

'Starts adding a new transfer.
Private Sub cmdNew_Click()
Dim frmTransferDetails As Form_frmTransferDetails
Set frmTransferDetails = Form_frmTransferDetails

'Call the procedure.
Call openForm(frmTransferDetails, "Add Transfer")
End Sub


'Opens the form. Accepts the form name and the form caption as parameters.
Public Sub openForm(frmOpenedForm As Form, strFormCaption As String)
'Dim frmOpenedForm As Form
Dim strFormName As String

strFormName = frmOpenedForm.Name

'Open the form.
DoCmd.openForm strFormName

'Set the form's caption.
frmOpenedForm.Caption = strFormCaption

'Clean up.
'frmOpenedForm = ""
strFormCaption = ""
strFormName = ""

End Sub

I can open the form, but the caption does not change. Any help would be
appreciated. Thanks.
 
Could you pass the desired caption in the OpenArgs of the form?
DoCmd.OpenForm "Form1", OpenArgs:="Add Transfer"

Then in the Load event of the form:
If Len(Me.OpenArgs) > 0 Then
Me.Caption = Me.OpenArgs
End If
 
Back
Top