Pass the form name to a dialogue

P

Peter Stone

Novice/XP/2003

I open a dialogue box (fdlgPublish) from a subform (fsubProgress) and update
various fields on the subform with the following code:

Private Sub cmdYesPublish_Click()
On Error GoTo Err_cmdYesPublish_Click
Forms!frmText!fsubProgress!cboPublicationStatusID = "3"
Forms!frmText!fsubProgress!txtRecordPublished = Date
Forms!frmText!fsubProgress!txtUpdateCycle = Me!cboPublish.Column(1)
Forms!frmText!fsubProgress!txtNextUpdateDue = Me!cboPublish
Forms!frmText!fsubProgress!cmdPublishUpdate.Caption = "Update"
Forms!frmText.Refresh
DoCmd.Close acForm, Me.Name
Exit_cmdYesPublish_Click:
Exit Sub

Err_cmdYesPublish_Click:
MsgBox Err.Description
Resume Exit_cmdYesPublish_Click

End Sub

So that I can use this dialogue with various forms, I would like to replace
frmText in the coding above with the name of the form that opened the
dialogue box.

From my reading, I believe this can be done using OpenArgs, but I can't find
an example or work out how.

In case it helps, here's the code that opens the dialogue box.

Private Sub cmdPublishUpdate_Click()
On Error GoTo Err_cmdPublishUpdate_Click
Dim stDocName As String
Dim stLinkCriteria As String
If cmdPublishUpdate.Caption = "Publish" Then
'if the record has never been Published
'open the PUBLISH dialogue
stDocName = "fdlgPublish"
Else
'open the UPDATE dialogue
stDocName = "fdlgUpdate"
End If
If bofProgress <> "9" Then
'the record hasn't been EDITED
'open the NOT EDITED message
stDocName = "fmsgNotEdited"
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdPublishUpdate_Click:
Exit Sub

Err_cmdPublishUpdate_Click:
MsgBox Err.Description
Resume Exit_cmdPublishUpdate_Click
End Sub

Thank you

Peter
 
B

Barry Gilbert

OpenArgs would be a good solution here. When you open the form, pass the name
of the calling form like this:

DoCmd.OpenForm FormName:=stDocName, WhereCondition:=stLinkCriteria,
OpenArgs:=Me.Name

Then in the YesPublish routine, do something like this:
Dim strFormName As String
strFormName = Me.OpenArgs
Forms(strFormName)!fsubProgress!Form!cboPublicationStatusID = "3"
Forms(strFormName)!fsubProgress!Form!txtRecordPublished = Date
Forms(strFormName)!fsubProgress!Form!txtUpdateCycle =
Me!cboPublish.Column(1)
Forms(strFormName)!fsubProgress!Form!txtNextUpdateDue = Me!cboPublish
Forms(strFormName)!fsubProgress!Form!cmdPublishUpdate.Caption = "Update"
Forms(strFormName).Refresh
DoCmd.Close acForm, Me.Name

Notice that I added !Form to the middle of the reference, This is required
to refer to controls on a subform. Of course, this assumes that the subform
is named the same wherever it's used.

Barry
 
P

Peter Stone

Dear Barry
I get a popup: Microsoft Access can't find the form 'fsubProgress' referrred
to in the VB code.

I'm sure it's something small but I can't solve it. I'm away for 6-7 hours
now.

Thank you

Peter
 
R

RoyVidar

Peter Stone said:
Dear Barry
I get a popup: Microsoft Access can't find the form 'fsubProgress'
referrred to in the VB code.

I'm sure it's something small but I can't solve it. I'm away for 6-7
hours now.

Thank you

Peter

I think the reason for the error, is that your code is in the subform,
and when you pass Me.Name, you pass the name of the subform, not
the main form on which it resides. You might pass something like

Me.Parent.Name ' or
Me.Parent.Form.Name

in stead, and see if that helps.

I think also that the suggested syntax

Forms(strFormName)!fsubProgress!Form!cboPublicationStatusID

could rather be

Forms(strFormName)!fsubProgress.Form!cboPublicationStatusID ' or
Forms(strFormName)!fsubProgress!cboPublicationStatusID

(note . in stead of ! in the first suggestion)
 
P

Peter Stone

Thank you Roy, Barry, & Roger

You first suggestion:
Me.Parent.Name
fixed it thank you Roy. The rest of the code that Barry gave me for the
dialogue box was correct.

This finishes Stage 1 of my project--thanks to all the help I've had on this
forum.

I recommend anyone looking for solutions to check out Roger's website--very
interesting. For some reason, I had never found it during my many searches.

Thanks again

Peter
 

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