OpenArgs not evaluated in Current event (1 Viewer)

GK in the UK

Registered User.
Local time
Today, 18:40
Joined
Dec 20, 2017
Messages
274
Is there any reason why I shouldn't evaluate OpenArgs in the current event ? As far as I can tell, it's not evaluated in there. Normally I have it in the load event but there's a reason I want it in Current, I want to refresh the contents of an already open form and I need to get the criteria for the opened record.


Edit: Title should read: OpenArgs not re-evaluated on subsequent OpenForm of already open form
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 18:40
Joined
Sep 21, 2011
Messages
14,046
Wouldn't a requery do that.?

Store the OpenArgs to a form global variable on load if it is not available in any other event.?
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:40
Joined
Sep 21, 2011
Messages
14,046
I've just tested it and it is available in the On Current event?
 

GK in the UK

Registered User.
Local time
Today, 18:40
Joined
Dec 20, 2017
Messages
274
Well I agree it's evaluated in Current when the form is first opened, that's where my OpenArgs evaluation code is.

So let's say I open frmInvoice with OpenArgs A then frmInvoice opens with OpenArgs A
If I close frmInvoice and reopen it with OpenArgs B then frmInvoice opens with OpenArgs B

But if I now leave frmInvoice open, and do OpenForm with OpenArgs A , frmInvoice doesn't re-evaluate OpenArgs and it's stuck on OpenArgs B. Open and Load don't fire so evaluation is in Current event.

No matter how many times I OpenForm with OpenArgs A, it's stuck on OpenArgs B. Even though evaluation is in Current. I have to close frmInvoice and start again which isn't what I want.

Ah, someone on StackOverflow says the same thing. No re-evaluation if the form is open. Need Plan B
 

isladogs

MVP / VIP
Local time
Today, 18:40
Joined
Jan 14, 2017
Messages
18,186
I've always used OpenArgs to set the form conditions when first loaded.
I don't believe it's intended for any other purpose.
https://docs.microsoft.com/en-us/office/vba/api/Access.Form.OpenArgs

For your situation why not just set filter criteria to the selected item e.g.
Me.Filter = ...some criteria
Me.FilterOn=True

Or use a subform filtered to the selection.
Lots of examples of both of these elsewhere in this forum
 

GK in the UK

Registered User.
Local time
Today, 18:40
Joined
Dec 20, 2017
Messages
274
Isn't a filter for record selection ? The child form is frmInvoice and is for a single record specified in WhereCondition.

The criteria is a) is this invoice editable (as opposed to finalised) and b) is this a Sales or Purch invoice, because the same frmInvoice deals with both and it needs to know how to display credit values - all to do with double entry book keeping)

For things like this I sometimes get the called form (frmInvoice) to read some values from hidden text boxes in the calling form. But in this case, I want to be able to open frmInvoice either from the index form, or stand alone from some other routine. So the criteria needs to come in via OpenArgs. frmIndex has to be a 'stand alone' object (if that's the right terminology)

The workaround is to close the form and immediately open it again. Seems like an ugly fix and it's really slow to browse the index file of invoices.


Thanks for your suggestions
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:40
Joined
Sep 21, 2011
Messages
14,046
If the form is already open, doesn't it just go to the form when you try a second open statement.?

You could use a Tempvar instead.?

If you want the form open multiple times, you need to setup a collection.?

Allen Brownes site shows how and it has been mentioned on here at least once.?

Well I agree it's evaluated in Current when the form is first opened, that's where my OpenArgs evaluation code is.

So let's say I open frmInvoice with OpenArgs A then frmInvoice opens with OpenArgs A
If I close frmInvoice and reopen it with OpenArgs B then frmInvoice opens with OpenArgs B

But if I now leave frmInvoice open, and do OpenForm with OpenArgs A , frmInvoice doesn't re-evaluate OpenArgs and it's stuck on OpenArgs B. Open and Load don't fire so evaluation is in Current event.

No matter how many times I OpenForm with OpenArgs A, it's stuck on OpenArgs B. Even though evaluation is in Current. I have to close frmInvoice and start again which isn't what I want.

Ah, someone on StackOverflow says the same thing. No re-evaluation if the form is open. Need Plan B
 

GK in the UK

Registered User.
Local time
Today, 18:40
Joined
Dec 20, 2017
Messages
274
It's the same instance of frmInvoice. I don't want another instance (though I will at some point so I'll have to understand that)

Thinking about it some more, I can probably determine the criteria from the document itself. Which is probably a much better way to do it but at least I now know the limitations of OpenArgs.
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:40
Joined
Sep 21, 2011
Messages
14,046
I do not think that is a limitation as you are not opening the form again?

A TempVar would probably do the job.?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:40
Joined
Sep 12, 2006
Messages
15,614
Obviously your problem is trying to refresh the data in an open form, where the form has been opened to show different data.

I would be inclined to find a way to force the popup form to close before opening it again - if you want to do this with openargs.

if you do it with a global variable (instead of the openargs) then you could call a function IN the popup form, to reload the data based on the global setting. However, you then maybe have an issue if the popup form is dirty.

Therefore, I would be inclined to close the popup form before opening it to a new record, (or find another way to accomplish the same thing)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:40
Joined
Feb 19, 2002
Messages
42,971
This is the reason that I hide formA when I open formB so that the user has to close formB before reopening it. If both formA and formB need to be visible, then I open formB as a dialog so that formA cannot get the focus while formB is still open.

When none of those will work, I have formA check to see if formB is already open and if it is, close it first. Then reopen it with the new openArg.
 

Micron

AWF VIP
Local time
Today, 14:40
Joined
Oct 20, 2018
Messages
3,476
then I open formB as a dialog so that formA cannot get the focus while formB is still open.
I think you mean modal? Dialog is a border property; popup and modal are form properties.
 

Micron

AWF VIP
Local time
Today, 14:40
Joined
Oct 20, 2018
Messages
3,476
TDG - no problem. Your point is well taken in that Pat might have been referring to window modes and not form views or properties.
 

GK in the UK

Registered User.
Local time
Today, 18:40
Joined
Dec 20, 2017
Messages
274
I suppose the clue about what OpenArgs does is in the name: I just expected to be able to re-evaluate it again without the re OPEN. Anyway the issue is solved; two of the parameters could be derived from the record itself within the form, the third one remained passed in OpenArgs but was static for the session.

I do keep the index form open along with the child form. The exception is when the user wants to add a NEW record from the index form, in that case, it tests for open and closes before re-opening with the new DataMode parameter.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:40
Joined
Oct 29, 2018
Messages
21,358
Unfortunately, I can't tell you the reason why MS decided to make OpenArgs read only. I guess it would have been nice to be able to update it sometimes. Good luck with your project.
 

Users who are viewing this thread

Top Bottom