By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,293 Members | 1,390 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,293 IT Pros & Developers. It's quick & easy.

Assigning Openargs to a "Form" Variable!

P: n/a
Hi All,

I am using the code below to assign a form name to a form variable (vFrm).
Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm =
Openargs ?

Private Sub Form_Load()
Public vFrm As Form

If Openargs = "subfrmProjects" then
vFrm = Form_subfrmProjects
ElseIf Openargs = "frmProjects" Then
Set vFrm = Form_frmProjects
ElseIf Openargs = "frmComponents" Then
Set vFrm = Form_frmComponents
End If

End Sub

Thanks for your assistance,
Barry
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Barry Edmund Wright wrote:
Hi All,

I am using the code below to assign a form name to a form variable (vFrm).
Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm =
Openargs ?

Private Sub Form_Load()
Public vFrm As Form

If Openargs = "subfrmProjects" then
vFrm = Form_subfrmProjects
ElseIf Openargs = "frmProjects" Then
Set vFrm = Form_frmProjects
ElseIf Openargs = "frmComponents" Then
Set vFrm = Form_frmComponents
End If

End Sub


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could do something like this:

-- Declaration section

' Declare a module level variable to hold the name of the
' calling form.
Dim m_strCallingForm As String

' An object reference variable that will hold the reference
' to the calling form object.
Dim m_frm As Form

Private Sub Form_Load()

m_strCallingForm = Me.OpenArgs

End Sub

' Where you need to set a form object variable to the calling form
' do this.

Set m_frm = Forms(m_strCallingForm)

This is what's known as "late binding." What you had been doing is
"early binding." Early binding is usually the preferred binding option
'cuz the compiler does all the binding of object methods/events before
the program runs. Late binding means the binding is done during the
program run and this can, possibly, slow down the processing. I've
found late binding to work well on most things I use it for. YMMV.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmPw+oechKqOuFEgEQLaKgCgnI39gRGBttv+b5ZGJm0383 awyWgAnR2I
WuPYyljBBjrtcJdQCDxa/UJM
=G1Tc
-----END PGP SIGNATURE-----
Nov 13 '05 #2

P: n/a
MG, that worked like a charm! And thanks for taking the time to expain about
the late-binding thingy!

Best regards,
Barry

"MGFoster" <me@privacy.com> wrote in message
news:Qh******************@newsread1.news.pas.earth link.net...
Barry Edmund Wright wrote:
Hi All,

I am using the code below to assign a form name to a form variable
(vFrm).
Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm
= Openargs ?

Private Sub Form_Load()
Public vFrm As Form

If Openargs = "subfrmProjects" then
vFrm = Form_subfrmProjects
ElseIf Openargs = "frmProjects" Then
Set vFrm = Form_frmProjects
ElseIf Openargs = "frmComponents" Then
Set vFrm = Form_frmComponents
End If

End Sub


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could do something like this:

-- Declaration section

' Declare a module level variable to hold the name of the
' calling form.
Dim m_strCallingForm As String

' An object reference variable that will hold the reference
' to the calling form object.
Dim m_frm As Form

Private Sub Form_Load()

m_strCallingForm = Me.OpenArgs

End Sub

' Where you need to set a form object variable to the calling form
' do this.

Set m_frm = Forms(m_strCallingForm)

This is what's known as "late binding." What you had been doing is
"early binding." Early binding is usually the preferred binding option
'cuz the compiler does all the binding of object methods/events before
the program runs. Late binding means the binding is done during the
program run and this can, possibly, slow down the processing. I've
found late binding to work well on most things I use it for. YMMV.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmPw+oechKqOuFEgEQLaKgCgnI39gRGBttv+b5ZGJm0383 awyWgAnR2I
WuPYyljBBjrtcJdQCDxa/UJM
=G1Tc
-----END PGP SIGNATURE-----

Nov 13 '05 #3

P: n/a
Sorry MG, I hadn't cleared out some of the old code, so the module wasn't
using new code.

When I try to assign the global string:

Set m_frm = Forms(m_strCallingForm)

I get run-time error '2450'
Database cannot find the form 'subfrmComp1' referred to in a macro
expression or Visual Basic code.

That's basically the problem I always get: I don't know how to assign a
"string" variable to a form using the Set statement.

Any thoughts on how to correct this error?
Thanks, Barry

"MGFoster" <me@privacy.com> wrote in message
news:Qh******************@newsread1.news.pas.earth link.net...
Barry Edmund Wright wrote:
Hi All,

I am using the code below to assign a form name to a form variable
(vFrm).
Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm
= Openargs ?

Private Sub Form_Load()
Public vFrm As Form

If Openargs = "subfrmProjects" then
vFrm = Form_subfrmProjects
ElseIf Openargs = "frmProjects" Then
Set vFrm = Form_frmProjects
ElseIf Openargs = "frmComponents" Then
Set vFrm = Form_frmComponents
End If

End Sub


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could do something like this:

-- Declaration section

' Declare a module level variable to hold the name of the
' calling form.
Dim m_strCallingForm As String

' An object reference variable that will hold the reference
' to the calling form object.
Dim m_frm As Form

Private Sub Form_Load()

m_strCallingForm = Me.OpenArgs

End Sub

' Where you need to set a form object variable to the calling form
' do this.

Set m_frm = Forms(m_strCallingForm)

This is what's known as "late binding." What you had been doing is
"early binding." Early binding is usually the preferred binding option
'cuz the compiler does all the binding of object methods/events before
the program runs. Late binding means the binding is done during the
program run and this can, possibly, slow down the processing. I've
found late binding to work well on most things I use it for. YMMV.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmPw+oechKqOuFEgEQLaKgCgnI39gRGBttv+b5ZGJm0383 awyWgAnR2I
WuPYyljBBjrtcJdQCDxa/UJM
=G1Tc
-----END PGP SIGNATURE-----

Nov 13 '05 #4

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

By the name of the form "subfrmComp1" I'm guessing that the form is
being used as a subform, correct? If so, you can't use my example to
set the m_frm variable to the name of the form when it is a subform in
another form. To set a form reference variable to a subform you have to
indicate where that subform is (in which form). E.g.:

Set m_frm = Forms(m_strCallingForm)!subFormName.Form

If the subform is a subform of a subform (nested 2 deep):

Set m_frm = Forms(m_strCallingForm)!subForm1Name!subForm2Name. Form

You can refer to subforms this way, too:

Set m_frm = Forms("form_name")("subform_name").Form

So if you could pass the calling main form name and its subform name in
the OpenArgs parameter (and parse them out) you could use the above
example to set the m_frm variable.

See the Access VBA Help article "Form Object." Open the Debug window
[Ctrl+G] and type in Forms, put the cursor on the word Forms & hit the
F1 key. Then click on the Form bar (bottom blue bar in the diagram at
the top of the Help page). At the bottom of the "Form Object" Help page
is a discussion of subforms & how to refer to them using VBA.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmUvaIechKqOuFEgEQIw8gCg8EFBZFNKM16J5uGsXx4gzL L1mvUAn0j/
7WX8YL2ld9CIfSB75/OOOVZv
=1xhm
-----END PGP SIGNATURE-----

Barry Edmund Wright wrote:
Sorry MG, I hadn't cleared out some of the old code, so the module wasn't
using new code.

When I try to assign the global string:

Set m_frm = Forms(m_strCallingForm)

I get run-time error '2450'
Database cannot find the form 'subfrmComp1' referred to in a macro
expression or Visual Basic code.

That's basically the problem I always get: I don't know how to assign a
"string" variable to a form using the Set statement.

Any thoughts on how to correct this error?
Thanks, Barry

"MGFoster" <me@privacy.com> wrote in message
news:Qh******************@newsread1.news.pas.earth link.net...
Barry Edmund Wright wrote:
Hi All,

I am using the code below to assign a form name to a form variable
(vFrm).
Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm
= Openargs ?

Private Sub Form_Load()
Public vFrm As Form

If Openargs = "subfrmProjects" then
vFrm = Form_subfrmProjects
ElseIf Openargs = "frmProjects" Then
Set vFrm = Form_frmProjects
ElseIf Openargs = "frmComponents" Then
Set vFrm = Form_frmComponents
End If

End Sub


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could do something like this:

-- Declaration section

' Declare a module level variable to hold the name of the
' calling form.
Dim m_strCallingForm As String

' An object reference variable that will hold the reference
' to the calling form object.
Dim m_frm As Form

Private Sub Form_Load()

m_strCallingForm = Me.OpenArgs

End Sub

' Where you need to set a form object variable to the calling form
' do this.

Set m_frm = Forms(m_strCallingForm)

This is what's known as "late binding." What you had been doing is
"early binding." Early binding is usually the preferred binding option
'cuz the compiler does all the binding of object methods/events before
the program runs. Late binding means the binding is done during the
program run and this can, possibly, slow down the processing. I've
found late binding to work well on most things I use it for. YMMV.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmPw+oechKqOuFEgEQLaKgCgnI39gRGBttv+b5ZGJm0383 awyWgAnR2I
WuPYyljBBjrtcJdQCDxa/UJM
=G1Tc
-----END PGP SIGNATURE-----


Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.