disappearing openargs value

  • Thread starter David via AccessMonster.com
  • Start date
D

David via AccessMonster.com

Hi,

I have a form that loses its OpenArgs value somewhere between editing the
data on the form and closing the form.

The calling form uses DoCmd.OpenForm and passes an opening argument that
contains a form or control name, the pipe character, and a code.

For example, the calling form has a command button (cmdDetails):
Code:
Private Sub cmdDetails_Click()
DoCmd.OpenForm "frmContactDetails", , , "pkautContactID = " &
Me.fkautContactID, , , "Forms!frmContactDetails!CAMPAIGNS.Form!
CAMPAIGNCONTACTLIST.Form|Det"
End Sub

This successfully opens frmContactDetails (and the filter on pkautContactID
works too). I have confirmed that the OpenArgs variable contains the string
sent to it using a Msgbox on the Open event. I can edit the data on the
form, and using another Msgbox, can see that the OpenArgs value is still
there.

***But when I close the form (either with DoCMd.Close or with the form's [X]
button), a Msgbox shows the OpenArgs value is blank and the code for the On
Close event gives me a Null error. I can certainly test for a null and deal
with it, but I use the OpenArgs value in the On Close event, so I need the
value to persist.

I could post the OpenArgs value to an hidden unbound textbox on the form,
but I am more interested in why the value is vanishing.

I can post the code behind the form, but it's fairly long & I don't see a
way to post an attachment on this BB.

Thanks in advance,
David
 
K

Ken Snell [MVP]

I don't have a technical reason/answer, but OpenArgs can lose its value
through many ways, including an unhandled error in the code. My guess is
that, as the form is closing, that property is one of the first ones
"destantiated".

I always write the OpenArgs value into a textbox on my forms so that I can
use it as needed while the form is open. This write action is among the
first lines of code in my form's Load event. So I recommend that, if you
want to use its value, you write the OpenArgs value to a hidden, unbound
textbox on the form...no way it's lost then until the form is unloaded.
 
G

Guest

Here is a simple solution that doesn't involve creating controls on your
form. Create a global value in the form code, then populate it when the form
is opened. You can then reference the value anytime just like you expect to
with the openargs.

Best of luck...
 
K

Ken Snell [MVP]

Global variables are prone to similar "loss of value" as are the OpenArgs
when an unhandled error (or other strange things) happens.


--

Ken Snell
<MS ACCESS MVP>

Devlin said:
Here is a simple solution that doesn't involve creating controls on your
form. Create a global value in the form code, then populate it when the
form
is opened. You can then reference the value anytime just like you expect
to
with the openargs.

Best of luck...

David via AccessMonster.com said:
Hi,

I have a form that loses its OpenArgs value somewhere between editing the
data on the form and closing the form.

The calling form uses DoCmd.OpenForm and passes an opening argument that
contains a form or control name, the pipe character, and a code.

For example, the calling form has a command button (cmdDetails):
Code:
Private Sub cmdDetails_Click()
DoCmd.OpenForm "frmContactDetails", , , "pkautContactID = " &
Me.fkautContactID, , , "Forms!frmContactDetails!CAMPAIGNS.Form!
CAMPAIGNCONTACTLIST.Form|Det"
End Sub

This successfully opens frmContactDetails (and the filter on
pkautContactID
works too). I have confirmed that the OpenArgs variable contains the
string
sent to it using a Msgbox on the Open event. I can edit the data on the
form, and using another Msgbox, can see that the OpenArgs value is still
there.

***But when I close the form (either with DoCMd.Close or with the form's
[X]
button), a Msgbox shows the OpenArgs value is blank and the code for the
On
Close event gives me a Null error. I can certainly test for a null and
deal
with it, but I use the OpenArgs value in the On Close event, so I need
the
value to persist.

I could post the OpenArgs value to an hidden unbound textbox on the form,
but I am more interested in why the value is vanishing.

I can post the code behind the form, but it's fairly long & I don't see a
way to post an attachment on this BB.

Thanks in advance,
David
 
D

David via AccessMonster.com

Thanks to you both.

I have checked for any unhandled errors, and don't think that is the
problem.

If I have to write the value to a textbox, I will, but it seems like an
unnecessary work-around. The variable shouldn't lose its value without
cause.

I'm open to any other ideas.

Thanks again,
David
 

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