OpenArgs with subform and other forms

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

Guest

I have a pop-up form which I am trying to get to open from either a subform
or another form. Once this form is open I then want to have it populate 2
fields from either the subform or another form. Both have the same field
names. I can get it to work with the other form. However, I am stuck trying
to get OpenArgs to open a form when clicking a button on a subform. I have
read a lot about OpenArgs today but nothing really dealing with my situation.
Can anyone suggest on how to go about doing this? Thanks in advance..
 
Post your code so we'll know what you've tried and give a little more
insight on what kind of problems you are having.

OpenArgs is simply a parameter that is used on the Docmd.Openform statement
which allows you to pass values into the called (or opened) form. It really
shouldn't matter whether the docmd.openform is being called from a main form
or a subform. If you'll post your code we can see what is happening.
 
Fysh,

You are thinking properly about forms. You want to design generic,
modular forms that can be used anywhere.

However, there is no simple answer for the specifics of how to get this
to work.

The cover story of the January issue of Access Advisor magazine, "Build
Better Microsoft Access Dialogs", addresses just the problem you have,
I think.

-Ken
 
Sandra, I have left work for the day and don't have the code with me. I will
post it tomorrow if there is no problem with that. However, I do want to
mentioned that I have tried several different techniques that I saw here when
I searched for OpenArgs, but none of them seem to work. One of the attempts
was something like DoCmd.OpenForm "frmComments",,,,,,OpenArgs:=Me.Name
But it couldn't find my subform which makes since. I should try to located
my main form then my subform. If I can get that part to work then passing
the variables should be easy would imagine. It just can't locate the
subform.

Once again I will post again tomorrow when I get back to work thanks again.
Also, thanks Ken by chance do you know of a location that I could find that
article?
 
Is Name the 'name' of the control on the subform which you are trying to
pass?

If so there are two problems - first you should not have fields or controls
which are named 'Name'. 'Name' a built in property of virtually every
object, including the form object so what you are really passing is the name
of the main form. (Granted, you might be trying to pass the name of the
form)

Second, still assuming that in your statement, me.Name is intended to supply
a value from the subform you must reference the subform through the subform
control which is on the mainform. The syntax is:

me.sfrmMySub.form.MyControl

Where 'sfrmMySub' is the name of the subform control (which is not
necessarily the same as the name of the form object referenced by the
subform control - ie the name you see in the database window and used in the
SourceObject property of the subform Control). To verify that you have the
correct name, click once on the subform control then look under the Name
property. Whatever you find there goes in place of 'sfrmMySub' above.
'MyControl' should be replaced with the name of the control on the subform.

Let me know whether this helps,
 
Ok
I have several different methods to open the pop up form form by clicking a
button on a subform without any luck. I have tried the following plus more

On another form I just use the following which works
DoCmd.OpenForm "frmComments", OpenArgs:=Me.Name

On the form to be opened I have
Me.Caption = Forms(Me.OpenArgs)![txtS1]

On the subform I have tried
DoCmd.OpenForm "frmComments" but on the pop-up I get mismatch error

Same with
DoCmd.OpenForm "frmComments", , , , , acDialog

Same with
DoCmd.OpenForm "frmComments", acNormal

Tried
DoCmd.OpenForm "frmComments", OpenArgs:=Me.Name pop-up can't find my subform

Tried
Dim strFormName As String
strFormName = frmEvaluation! & frmEvaluationSubform
DoCmd.OpenForm "frmComments", OpenArgs:=strFormName
Pop-up can't find the form 0

Tried
Dim strFormName As String
strFormName = "frmEvaluation!" & "frmEvaluationSubform"
DoCmd.OpenForm "frmComments", OpenArgs:=strFormName
Pop-up can't find the form frmEvaluation!frmEvaluationSubform

Same type of message when I use
strFormName = "Forms!" & "frmEvaluation!" & "frmEvaluationSubform"

or
strFormName = "Forms!" & "frmEvaluation!" & "frmEvaluationSubform." & "Form"

I also tried more lengthy ones, but still no luck. I hope you can help,
thanks.
 
I would rather just have it open the pop-up and with OpenArgs pull in the
fields that I need for that form. Similiar to when I open it up with just
another form.

Sandra Daigle said:
Is Name the 'name' of the control on the subform which you are trying to
pass?

If so there are two problems - first you should not have fields or controls
which are named 'Name'. 'Name' a built in property of virtually every
object, including the form object so what you are really passing is the name
of the main form. (Granted, you might be trying to pass the name of the
form)

Second, still assuming that in your statement, me.Name is intended to supply
a value from the subform you must reference the subform through the subform
control which is on the mainform. The syntax is:

me.sfrmMySub.form.MyControl

Where 'sfrmMySub' is the name of the subform control (which is not
necessarily the same as the name of the form object referenced by the
subform control - ie the name you see in the database window and used in the
SourceObject property of the subform Control). To verify that you have the
correct name, click once on the subform control then look under the Name
property. Whatever you find there goes in place of 'sfrmMySub' above.
'MyControl' should be replaced with the name of the control on the subform.

Let me know whether this helps,


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Sandra, I have left work for the day and don't have the code with me. I
will post it tomorrow if there is no problem with that. However, I do
want to mentioned that I have tried several different techniques that I
saw here when I searched for OpenArgs, but none of them seem to work.
One of the attempts was something like DoCmd.OpenForm
"frmComments",,,,,,OpenArgs:=Me.Name But it couldn't find my subform
which makes since. I should try to located my main form then my subform.
If I can get that part to work then passing the variables should be easy
would imagine. It just can't locate the subform.

Once again I will post again tomorrow when I get back to work thanks
again. Also, thanks Ken by chance do you know of a location that I could
find that article?
 
I failed to mention the 'Name' is the name of the subform I am trying to
pass. Also, I wonder if it has to do with the fact the subform is unbound
and thus not linked to the main form.

Sandra Daigle said:
Is Name the 'name' of the control on the subform which you are trying to
pass?

If so there are two problems - first you should not have fields or controls
which are named 'Name'. 'Name' a built in property of virtually every
object, including the form object so what you are really passing is the name
of the main form. (Granted, you might be trying to pass the name of the
form)

Second, still assuming that in your statement, me.Name is intended to supply
a value from the subform you must reference the subform through the subform
control which is on the mainform. The syntax is:

me.sfrmMySub.form.MyControl

Where 'sfrmMySub' is the name of the subform control (which is not
necessarily the same as the name of the form object referenced by the
subform control - ie the name you see in the database window and used in the
SourceObject property of the subform Control). To verify that you have the
correct name, click once on the subform control then look under the Name
property. Whatever you find there goes in place of 'sfrmMySub' above.
'MyControl' should be replaced with the name of the control on the subform.

Let me know whether this helps,


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Sandra, I have left work for the day and don't have the code with me. I
will post it tomorrow if there is no problem with that. However, I do
want to mentioned that I have tried several different techniques that I
saw here when I searched for OpenArgs, but none of them seem to work.
One of the attempts was something like DoCmd.OpenForm
"frmComments",,,,,,OpenArgs:=Me.Name But it couldn't find my subform
which makes since. I should try to located my main form then my subform.
If I can get that part to work then passing the variables should be easy
would imagine. It just can't locate the subform.

Once again I will post again tomorrow when I get back to work thanks
again. Also, thanks Ken by chance do you know of a location that I could
find that article?
 
Ok Sandra maybe I am looking at this all wrong, but I am still not able to
get this to work. When I try your method it gives me a compile error. This
is getting frustrating.....

Sandra Daigle said:
Is Name the 'name' of the control on the subform which you are trying to
pass?

If so there are two problems - first you should not have fields or controls
which are named 'Name'. 'Name' a built in property of virtually every
object, including the form object so what you are really passing is the name
of the main form. (Granted, you might be trying to pass the name of the
form)

Second, still assuming that in your statement, me.Name is intended to supply
a value from the subform you must reference the subform through the subform
control which is on the mainform. The syntax is:

me.sfrmMySub.form.MyControl

Where 'sfrmMySub' is the name of the subform control (which is not
necessarily the same as the name of the form object referenced by the
subform control - ie the name you see in the database window and used in the
SourceObject property of the subform Control). To verify that you have the
correct name, click once on the subform control then look under the Name
property. Whatever you find there goes in place of 'sfrmMySub' above.
'MyControl' should be replaced with the name of the control on the subform.

Let me know whether this helps,


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Sandra, I have left work for the day and don't have the code with me. I
will post it tomorrow if there is no problem with that. However, I do
want to mentioned that I have tried several different techniques that I
saw here when I searched for OpenArgs, but none of them seem to work.
One of the attempts was something like DoCmd.OpenForm
"frmComments",,,,,,OpenArgs:=Me.Name But it couldn't find my subform
which makes since. I should try to located my main form then my subform.
If I can get that part to work then passing the variables should be easy
would imagine. It just can't locate the subform.

Once again I will post again tomorrow when I get back to work thanks
again. Also, thanks Ken by chance do you know of a location that I could
find that article?
 
Sorry to take so long in getting back to you, the last few days have been a
little hectic. After reading your last posts I believe I understand what you
are trying to do and I also understand why you are having trouble doing it.
You are using OpenArgs to pass the name of the calling form and then using
that name, you are referencing back to a control on calling form. The reason
your code won't work is that a subform is not open by itself and any
references to it or its properties or controls must be made through the
parent form and you must have the name of the subform control to get to the
subform. While possible, it may be more trouble than it is worth.

Instead you might want to consider passing the value (or values) to the
called form using a delimited string which you break apart in the called
form using the Split function. If you want to procede using only the name of
the form then you will need a stategy that allows you to get to the subform.
Because you really need the name of the subform control AND the name of the
parent form the code is a bit more complex. Here is code that creates the
openArgs string with the name of the mainform with the subform control name
when the form is opened as a subform. When the form is not opened a subform
it passes only the form name.

* This goes in the calling form/subform
Dim ctl As Control
Dim strOpenArgs As String
If IsSubForm(Me) Then
For Each ctl In Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form.hWnd = Me.hWnd Then
strOpenArgs = Me.Parent.Name & "," & ctl.Name
End If
End If
Next
Else
strOpenArgs = Me.Name
End If
DoCmd.OpenForm "frmTestOpenArgs", , , , , , strOpenArgs
End Sub

* This goes in a standard module

Public Function IsSubForm(pFrm As Form) As Boolean
' Comments :
' Parameters: pFrm -
' Returns : Boolean
' Modified : 07/31/2000 SMD
'

' Is the form referenced in the
' parameter currently loaded as a subform?
' Check its Parent property to find out.
' In:
' frm: a reference to the form in question
' Out:
' Return value: True if the form is a subform
' False if it's a standalone form

Dim strName As String
On Error Resume Next
strName = pFrm.Parent.Name
IsSubForm = (Err = 0)
End Function

Of course the called form has to be able to handle the additional
information so here's how this code should look:

Private Sub Form_Open(Cancel As Integer)
Dim strArgs() As String
dim strSubFormCtlName as string
dim strFormName as string

If Len(Me.OpenArgs & "") > 0 Then
strArgs = Split(Me.OpenArgs, ",")
strFormName = strArgs(0)
If UBound(strArgs) > 0 Then
strSubFormCtlName = strArgs(1)
msgbox "The Custid on the subform is: " &
Forms(Me.txtFormName).Form.Controls(Me.txtSubFormCtlName)!Custid
Else
msgbox "The Custid on the subform is: " &
Forms(Me.txtFormName)!Custid
End If
End If

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
I failed to mention the 'Name' is the name of the subform I am trying to
pass. Also, I wonder if it has to do with the fact the subform is unbound
and thus not linked to the main form.

Sandra Daigle said:
Is Name the 'name' of the control on the subform which you are trying to
pass?

If so there are two problems - first you should not have fields or
controls which are named 'Name'. 'Name' a built in property of virtually
every object, including the form object so what you are really passing
is the name of the main form. (Granted, you might be trying to pass the
name of the form)

Second, still assuming that in your statement, me.Name is intended to
supply a value from the subform you must reference the subform through
the subform control which is on the mainform. The syntax is:

me.sfrmMySub.form.MyControl

Where 'sfrmMySub' is the name of the subform control (which is not
necessarily the same as the name of the form object referenced by the
subform control - ie the name you see in the database window and used in
the SourceObject property of the subform Control). To verify that you
have the correct name, click once on the subform control then look under
the Name property. Whatever you find there goes in place of 'sfrmMySub'
above. 'MyControl' should be replaced with the name of the control on
the subform.

Let me know whether this helps,


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Sandra, I have left work for the day and don't have the code with me. I
will post it tomorrow if there is no problem with that. However, I do
want to mentioned that I have tried several different techniques that I
saw here when I searched for OpenArgs, but none of them seem to work.
One of the attempts was something like DoCmd.OpenForm
"frmComments",,,,,,OpenArgs:=Me.Name But it couldn't find my subform
which makes since. I should try to located my main form then my
subform. If I can get that part to work then passing the variables
should be easy would imagine. It just can't locate the subform.

Once again I will post again tomorrow when I get back to work thanks
again. Also, thanks Ken by chance do you know of a location that I could
find that article?

:

I have a pop-up form which I am trying to get to open from either a
subform or another form. Once this form is open I then want to have it
populate 2 fields from either the subform or another form. Both have
the same field names. I can get it to work with the other form.
However, I am stuck trying to get OpenArgs to open a form when clicking
a button on a subform. I have read a lot about OpenArgs today but
nothing really dealing with my situation. Can anyone suggest on how to
go about doing this? Thanks in advance..
 
Thanks for the reply. I actually ended up using a different method which
worked. I will keep your notes for future use. Thanks again.

Sandra Daigle said:
Sorry to take so long in getting back to you, the last few days have been a
little hectic. After reading your last posts I believe I understand what you
are trying to do and I also understand why you are having trouble doing it.
You are using OpenArgs to pass the name of the calling form and then using
that name, you are referencing back to a control on calling form. The reason
your code won't work is that a subform is not open by itself and any
references to it or its properties or controls must be made through the
parent form and you must have the name of the subform control to get to the
subform. While possible, it may be more trouble than it is worth.

Instead you might want to consider passing the value (or values) to the
called form using a delimited string which you break apart in the called
form using the Split function. If you want to procede using only the name of
the form then you will need a stategy that allows you to get to the subform.
Because you really need the name of the subform control AND the name of the
parent form the code is a bit more complex. Here is code that creates the
openArgs string with the name of the mainform with the subform control name
when the form is opened as a subform. When the form is not opened a subform
it passes only the form name.

* This goes in the calling form/subform
Dim ctl As Control
Dim strOpenArgs As String
If IsSubForm(Me) Then
For Each ctl In Parent.Controls
If ctl.ControlType = acSubform Then
If ctl.Form.hWnd = Me.hWnd Then
strOpenArgs = Me.Parent.Name & "," & ctl.Name
End If
End If
Next
Else
strOpenArgs = Me.Name
End If
DoCmd.OpenForm "frmTestOpenArgs", , , , , , strOpenArgs
End Sub

* This goes in a standard module

Public Function IsSubForm(pFrm As Form) As Boolean
' Comments :
' Parameters: pFrm -
' Returns : Boolean
' Modified : 07/31/2000 SMD
'

' Is the form referenced in the
' parameter currently loaded as a subform?
' Check its Parent property to find out.
' In:
' frm: a reference to the form in question
' Out:
' Return value: True if the form is a subform
' False if it's a standalone form

Dim strName As String
On Error Resume Next
strName = pFrm.Parent.Name
IsSubForm = (Err = 0)
End Function

Of course the called form has to be able to handle the additional
information so here's how this code should look:

Private Sub Form_Open(Cancel As Integer)
Dim strArgs() As String
dim strSubFormCtlName as string
dim strFormName as string

If Len(Me.OpenArgs & "") > 0 Then
strArgs = Split(Me.OpenArgs, ",")
strFormName = strArgs(0)
If UBound(strArgs) > 0 Then
strSubFormCtlName = strArgs(1)
msgbox "The Custid on the subform is: " &
Forms(Me.txtFormName).Form.Controls(Me.txtSubFormCtlName)!Custid
Else
msgbox "The Custid on the subform is: " &
Forms(Me.txtFormName)!Custid
End If
End If

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
I failed to mention the 'Name' is the name of the subform I am trying to
pass. Also, I wonder if it has to do with the fact the subform is unbound
and thus not linked to the main form.

Sandra Daigle said:
Is Name the 'name' of the control on the subform which you are trying to
pass?

If so there are two problems - first you should not have fields or
controls which are named 'Name'. 'Name' a built in property of virtually
every object, including the form object so what you are really passing
is the name of the main form. (Granted, you might be trying to pass the
name of the form)

Second, still assuming that in your statement, me.Name is intended to
supply a value from the subform you must reference the subform through
the subform control which is on the mainform. The syntax is:

me.sfrmMySub.form.MyControl

Where 'sfrmMySub' is the name of the subform control (which is not
necessarily the same as the name of the form object referenced by the
subform control - ie the name you see in the database window and used in
the SourceObject property of the subform Control). To verify that you
have the correct name, click once on the subform control then look under
the Name property. Whatever you find there goes in place of 'sfrmMySub'
above. 'MyControl' should be replaced with the name of the control on
the subform.

Let me know whether this helps,


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Fysh wrote:
Sandra, I have left work for the day and don't have the code with me. I
will post it tomorrow if there is no problem with that. However, I do
want to mentioned that I have tried several different techniques that I
saw here when I searched for OpenArgs, but none of them seem to work.
One of the attempts was something like DoCmd.OpenForm
"frmComments",,,,,,OpenArgs:=Me.Name But it couldn't find my subform
which makes since. I should try to located my main form then my
subform. If I can get that part to work then passing the variables
should be easy would imagine. It just can't locate the subform.

Once again I will post again tomorrow when I get back to work thanks
again. Also, thanks Ken by chance do you know of a location that I could
find that article?

:

I have a pop-up form which I am trying to get to open from either a
subform or another form. Once this form is open I then want to have it
populate 2 fields from either the subform or another form. Both have
the same field names. I can get it to work with the other form.
However, I am stuck trying to get OpenArgs to open a form when clicking
a button on a subform. I have read a lot about OpenArgs today but
nothing really dealing with my situation. Can anyone suggest on how to
go about doing this? Thanks in advance..
 
Back
Top