Dynamic Form Caption

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.
 
A

Allen Browne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top