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

Building an expressions where parts are unknown at design time

P: n/a
I want the value of [ContactID] of the Calling form Form1.
How do I do this?

===============================
'Some Form (the calling form Form1)

Private Sub cmdOpenForm2_Click()
Dim strNameOfForm1 As String
strNameOfForm1 = Me.Name
DoCmd.OpenForm "Form2", , , , , , strNameOfForm1
End Sub
===============================

===============================
'Called Form (the called form Form2)

Private Sub Form2_Load()
If Not IsNull(Me.OpenArgs) Then

Dim strNameOfCallingForm As String
Dim ContactIDFromCallingForm

'Get the open arguments
'(The name of the form that called this form)
strNameOfCallingForm = Me.OpenArgs

'Find the value of the ContactID of the source form
'You can see below what I am trying to do
'But how do I do it????
'I need both the name of the calling form and an ID from that form
ContactIDFromCallingForm = Forms![Me.OpenArgs]![ContactID]

'Do other things
'Use strNameOfCallingForm for other things
'Use ContactIDFromCallingForm for other things
Else
'Do nothing
End If

End Sub
===============================

Yes, I can write a case statement with all the possibilities provided,
and all the possible expressions.
There are other convoluted ways too, but is that the most elegant way?
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Douglas Buchanan" <db*********@comcast.net> wrote in message
news:db*************************@posting.google.co m...
I want the value of [ContactID] of the Calling form Form1.
How do I do this?

===============================
'Some Form (the calling form Form1)

Private Sub cmdOpenForm2_Click()
Dim strNameOfForm1 As String
strNameOfForm1 = Me.Name
DoCmd.OpenForm "Form2", , , , , , strNameOfForm1
End Sub
===============================

===============================
'Called Form (the called form Form2)

Private Sub Form2_Load()
If Not IsNull(Me.OpenArgs) Then

Dim strNameOfCallingForm As String
Dim ContactIDFromCallingForm

'Get the open arguments
'(The name of the form that called this form)
strNameOfCallingForm = Me.OpenArgs

'Find the value of the ContactID of the source form
'You can see below what I am trying to do
'But how do I do it????
'I need both the name of the calling form and an ID from that form
ContactIDFromCallingForm = Forms![Me.OpenArgs]![ContactID]

'Do other things
'Use strNameOfCallingForm for other things
'Use ContactIDFromCallingForm for other things
Else
'Do nothing
End If

End Sub
===============================

Yes, I can write a case statement with all the possibilities provided,
and all the possible expressions.
There are other convoluted ways too, but is that the most elegant way?



Have you considered combining more than one piece of information in the
OpenArgs string?

Dim strOpenArgs As String
strOpenArgs = Me.Name & "|" & Nz(Me!ContactID,0)
DoCmd.OpenForm "Form2", , , , , , strOpenArgs

Then you extract them using the split function (if you have A2K onwards - if
not, you can write an A97 version)

strOpenArgs = Nz(Me.OpenArgs)
If Len(strOpenArgs)=0 Then Exit Sub
astrValues = Split(strOpenArgs, "|")
MsgBox "Form Name: " & astrValues(0) & vbCrLf & _
"Contact ID: " & astrValues(1)
Fletcher
Nov 12 '05 #2

P: n/a
On Wed, 11 Feb 2004 09:42:58 +0000 (UTC), "Fletcher Arnold"
<fl****@home.com> wrote:

<clip>
Yes, or better yet use a querystring-like format that is also
self-describing:
<key1>=<value1>&<key2>=<value2>

In VB I use a Scripting.Dictionary object to simulate OpenArgs. Could
probably use that in Access as well.

-Tom.



Have you considered combining more than one piece of information in the
OpenArgs string?

Dim strOpenArgs As String
strOpenArgs = Me.Name & "|" & Nz(Me!ContactID,0)
DoCmd.OpenForm "Form2", , , , , , strOpenArgs

Then you extract them using the split function (if you have A2K onwards - if
not, you can write an A97 version)

strOpenArgs = Nz(Me.OpenArgs)
If Len(strOpenArgs)=0 Then Exit Sub
astrValues = Split(strOpenArgs, "|")
MsgBox "Form Name: " & astrValues(0) & vbCrLf & _
"Contact ID: " & astrValues(1)
Fletcher


Nov 12 '05 #3

P: n/a
"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:ih********************************@4ax.com...
On Wed, 11 Feb 2004 09:42:58 +0000 (UTC), "Fletcher Arnold"
<fl****@home.com> wrote:

<clip>
Yes, or better yet use a querystring-like format that is also
self-describing:
<key1>=<value1>&<key2>=<value2>

In VB I use a Scripting.Dictionary object to simulate OpenArgs. Could
probably use that in Access as well.

-Tom.

Certainly. Passing a string of "FormName=frmMyForm&ContactID=1024" would
make it a lot clearer than extracting values astrValues(0) and
strValues(1) - which is not very self-explanatory.

Fletcher

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.