OpenForm: multiple OpenArgs

G

Gary Dolliver

Hi all,
Sorry, I have not been able to find out how to do this, yet it should be
very simple. I am opening another form (formB) and trying to pass multiple
text box values from formA to formB. I am using the following:
DoCmd.OpenForm "CS_Email_Form", , , , , , [Contact_Email].Value
which works great. However, if I try to pass multiple fields (ie, Order_ID
and Contact_Email) it begins requesting that I put quotes around the fields
(I am not able to get out of the VBA editor)- but once I doput the quotes
around my OpenArgs, it then just passes the text inside the quotes, and not
the values from FormA. I have tried creating variables, but the same thing
happens. Is there a special way to make the quotes so that I may pass
multiple values to formB? Any help is always appreciated, thanks!
-gary
 
S

Stefan Hoffmann

hi Gary,

Gary said:
Is there a special way to make the quotes so that I may pass
multiple values to formB? Any help is always appreciated, thanks!

OpenArgs := Value & Delimiter & Value & Delimter & Value

use Split() to seperate the values:

Dim OpenArgStings() As String

OpenArgStings() = Split(OpenArgs, Delimiter)

As the delimiter may not be part of the payload you need to escape it, e.g.

Value = Replace(OrigValue, _
Delimiter, _
Delimiter & Delimiter)

and

OrigValue = Replace(OpenArgsStrings(x), _
Delimiter & Delimiter, _
Delimiter)


mfG
--> stefan <--
 
A

Andy Hull

Hi Gary

You can only pass one "thing" via openargs although that "thing" could be
several values concatenated into a single string with suitable separators.
So you could pass one string and then use vba in the opening form to split it
into its parts again.

However, if your calling form is, say, MyForm then the opening form can use
the values directly using the following syntax...

[Forms]![MyForm].[Order_ID] and [Forms]![MyForm].[Contact_Email]

As long as the calling form stays open.

hth

Andy Hull
 
K

Klatuu

As Andy said, only one text value can be passed in the OpenArgs and reading
values directly from the other form, provided it is open, is an option. If
you want to pass all the value in one string and parse it out, the best way
is to use the Split function. It creates an array of strings in a Variant
variable using a delimiter. For example, if you have strThing = "A/B/C" and
call the Split Funtion:

varStuff = Split(strThing, "/")
varStuff will now contain 3 elements
varStuff(0) will = "A"
varStuff(1) will = "B"
varStuff(2) will = "C"
 
G

Gary Dolliver

Hi Andy,
Thanks for the reply, that makes sense. I may be able to use the "open
form" method, however, I will be calling this one form (formB) from 2
different forms. Is it possible to have an "if" statement that
if formA is open
[Forms]![FormA].[Order_ID] and [Forms]![FormA].[Contact_Email]
elseif formC is open
[Forms]![FormC].[Order_ID] and [Forms]![FormC].[Contact_Email]
end if
???? thank you so much for the reply!
-gary


Andy Hull said:
Hi Gary

You can only pass one "thing" via openargs although that "thing" could be
several values concatenated into a single string with suitable separators.
So you could pass one string and then use vba in the opening form to split it
into its parts again.

However, if your calling form is, say, MyForm then the opening form can use
the values directly using the following syntax...

[Forms]![MyForm].[Order_ID] and [Forms]![MyForm].[Contact_Email]

As long as the calling form stays open.

hth

Andy Hull


Gary Dolliver said:
Hi all,
Sorry, I have not been able to find out how to do this, yet it should be
very simple. I am opening another form (formB) and trying to pass multiple
text box values from formA to formB. I am using the following:
DoCmd.OpenForm "CS_Email_Form", , , , , , [Contact_Email].Value
which works great. However, if I try to pass multiple fields (ie, Order_ID
and Contact_Email) it begins requesting that I put quotes around the fields
(I am not able to get out of the VBA editor)- but once I doput the quotes
around my OpenArgs, it then just passes the text inside the quotes, and not
the values from FormA. I have tried creating variables, but the same thing
happens. Is there a special way to make the quotes so that I may pass
multiple values to formB? Any help is always appreciated, thanks!
-gary
 
K

Klatuu

The answer is yes.
One way would be to pass the name of the Calling form to the form you are
opening. If you want to test to see if a form is open, the syntax is

If CurrentProject.Allforms("FormA").Isloaded Then

--
Dave Hargis, Microsoft Access MVP


Gary Dolliver said:
Hi Andy,
Thanks for the reply, that makes sense. I may be able to use the "open
form" method, however, I will be calling this one form (formB) from 2
different forms. Is it possible to have an "if" statement that
if formA is open
[Forms]![FormA].[Order_ID] and [Forms]![FormA].[Contact_Email]
elseif formC is open
[Forms]![FormC].[Order_ID] and [Forms]![FormC].[Contact_Email]
end if
???? thank you so much for the reply!
-gary


Andy Hull said:
Hi Gary

You can only pass one "thing" via openargs although that "thing" could be
several values concatenated into a single string with suitable separators.
So you could pass one string and then use vba in the opening form to split it
into its parts again.

However, if your calling form is, say, MyForm then the opening form can use
the values directly using the following syntax...

[Forms]![MyForm].[Order_ID] and [Forms]![MyForm].[Contact_Email]

As long as the calling form stays open.

hth

Andy Hull


Gary Dolliver said:
Hi all,
Sorry, I have not been able to find out how to do this, yet it should be
very simple. I am opening another form (formB) and trying to pass multiple
text box values from formA to formB. I am using the following:
DoCmd.OpenForm "CS_Email_Form", , , , , , [Contact_Email].Value
which works great. However, if I try to pass multiple fields (ie, Order_ID
and Contact_Email) it begins requesting that I put quotes around the fields
(I am not able to get out of the VBA editor)- but once I doput the quotes
around my OpenArgs, it then just passes the text inside the quotes, and not
the values from FormA. I have tried creating variables, but the same thing
happens. Is there a special way to make the quotes so that I may pass
multiple values to formB? Any help is always appreciated, thanks!
-gary
 
G

Gary Dolliver

Awesome! Thank you! I passed a string value of all the fields I wanted and
then split it on the "onLoad" event for opening the second form, with the
following:
varSplitString = Split([StringPass], "/")
Me.[Recipient].Value = varSplitString(0)
Me.[Order_ID].Value = varSplitString(1)
My fields populated and all is well, thank you so much!
-gary

Klatuu said:
As Andy said, only one text value can be passed in the OpenArgs and reading
values directly from the other form, provided it is open, is an option. If
you want to pass all the value in one string and parse it out, the best way
is to use the Split function. It creates an array of strings in a Variant
variable using a delimiter. For example, if you have strThing = "A/B/C" and
call the Split Funtion:

varStuff = Split(strThing, "/")
varStuff will now contain 3 elements
varStuff(0) will = "A"
varStuff(1) will = "B"
varStuff(2) will = "C"
--
Dave Hargis, Microsoft Access MVP


Gary Dolliver said:
Hi all,
Sorry, I have not been able to find out how to do this, yet it should be
very simple. I am opening another form (formB) and trying to pass multiple
text box values from formA to formB. I am using the following:
DoCmd.OpenForm "CS_Email_Form", , , , , , [Contact_Email].Value
which works great. However, if I try to pass multiple fields (ie, Order_ID
and Contact_Email) it begins requesting that I put quotes around the fields
(I am not able to get out of the VBA editor)- but once I doput the quotes
around my OpenArgs, it then just passes the text inside the quotes, and not
the values from FormA. I have tried creating variables, but the same thing
happens. Is there a special way to make the quotes so that I may pass
multiple values to formB? Any help is always appreciated, thanks!
-gary
 
G

Gary Dolliver

Wow, thank you - that works! One more, what if both forms are open? (as one
form is an order entry form and the other an inquiry form, and there may be
instances of both being open and on different records) - is there a way to
have the form being opened only relate to the form that called it to be
opened?
thanks again!
-gary

Klatuu said:
The answer is yes.
One way would be to pass the name of the Calling form to the form you are
opening. If you want to test to see if a form is open, the syntax is

If CurrentProject.Allforms("FormA").Isloaded Then

--
Dave Hargis, Microsoft Access MVP


Gary Dolliver said:
Hi Andy,
Thanks for the reply, that makes sense. I may be able to use the "open
form" method, however, I will be calling this one form (formB) from 2
different forms. Is it possible to have an "if" statement that
if formA is open
[Forms]![FormA].[Order_ID] and [Forms]![FormA].[Contact_Email]
elseif formC is open
[Forms]![FormC].[Order_ID] and [Forms]![FormC].[Contact_Email]
end if
???? thank you so much for the reply!
-gary


Andy Hull said:
Hi Gary

You can only pass one "thing" via openargs although that "thing" could be
several values concatenated into a single string with suitable separators.
So you could pass one string and then use vba in the opening form to split it
into its parts again.

However, if your calling form is, say, MyForm then the opening form can use
the values directly using the following syntax...

[Forms]![MyForm].[Order_ID] and [Forms]![MyForm].[Contact_Email]

As long as the calling form stays open.

hth

Andy Hull


:

Hi all,
Sorry, I have not been able to find out how to do this, yet it should be
very simple. I am opening another form (formB) and trying to pass multiple
text box values from formA to formB. I am using the following:
DoCmd.OpenForm "CS_Email_Form", , , , , , [Contact_Email].Value
which works great. However, if I try to pass multiple fields (ie, Order_ID
and Contact_Email) it begins requesting that I put quotes around the fields
(I am not able to get out of the VBA editor)- but once I doput the quotes
around my OpenArgs, it then just passes the text inside the quotes, and not
the values from FormA. I have tried creating variables, but the same thing
happens. Is there a special way to make the quotes so that I may pass
multiple values to formB? Any help is always appreciated, thanks!
-gary
 

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