Modal Property Let (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 00:43
Joined
Oct 30, 2008
Messages
891
Just wondering if a Form is opened modally, can Property Let be used anyhow?
Or is Open args the only way to send values to the Form ?
Thanks.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:43
Joined
Jul 9, 2003
Messages
11,633
Just wondering if a Form is opened modally, can Property Let be used anyhow?
Or is Open args the only way to send values to the Form ?
Thanks.
I don't see how you can send any information into a modal form once it's opened. You cannot access any of your other forms because the modal form locks everything down, that means you can't trigger an event to pass information into the modal form because there's no buttons, no"Events" that you'll be allowed to press/run, unless you're running some sort of automated routine behind the scenes?

I suspect you mean the form is closed, and you want to pass information into a modal form as you open it, then yes, you can use custom property statements to store the information in the form. However you cannot manipulate the information in the custom properties with the forms load event, or indeed any of the other events that happened when the form opens, this is because the information isn't available in the custom properties for some strange reason! Maybe this is the issue you are having with the opening of it.

In this case then indeed open-args does work, however you can still use the information passed into the property statements, what you do is you set up your own public function within the form, I usually call it "function setup" fSetUp... as you open the form you call the function "fSetUp". Pass the information into to the custom properties, and then run the public function.

I think I've covered this in some YouTube videos, I'll see if I can find them!
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:43
Joined
Jul 9, 2003
Messages
11,633
I think I've covered this in some YouTube videos, I'll see if I can find them!
Yes! I did cover it in a video, not sure if it's absolutely clear. If you've got any questions by all means ask me. Here's the video:-

3) - OOP's - Creating A Class Step 1 - Nifty Access
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:43
Joined
Jul 9, 2003
Messages
11,633
The video I posted above, is also on my website here (Video 4 (2:00) Approx!):-

Open One Form From Another

along with several other videos exploring this issue, amongst others.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:43
Joined
Jul 9, 2003
Messages
11,633
I think the real issue is the "Form Load Event" ...

When I first started with VBA code I found the form load event very handy, I employed it to modify my forms as they loaded. I seldom use the forms open event, although I do use it for a loading class modules, but I can't remember why? I mean, what IS the difference is between the two events? "Form Load" & "Form Open"...

You can fall into the trap of thinking that the form load Event is the only way of getting things to happen on the form when it opens. I was in this track for years, and then the problem arose where I was trying to use custom properties and I couldn't, because the load event runs before the properties are set, in fact NONE of the forms events run after the custom properties are set! Very strange I thought. After a lot of head scratching I realised I could create my own public function "fSetUp" --- simple, done!

I wonder from time to time, what is the logic behind Microsoft's decision not to allow you to call custom properties with the forms "beginning" events? Is it done deliberately or by accident?

It seems to me that the logical approach is to separate the form construction and form function. In looking at it this way, then you could assume that the form open, form load, all the other "initialising events" of the form should be used to control the fundamental processes and condition of the basic form, not the business logic of the form. Separate the business logic out to the public functions.?

That's my take on it, love to hear counter views and corrections, I'm sure I will get some!

MORE INFO HERE:-
Open One Form From Another
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:43
Joined
May 21, 2018
Messages
3,183
ust wondering if a Form is opened modally, can Property Let be used anyhow?
I am not sure the reason for the long diatribe, but the answer is YES, you can manipulate a form open Modal and even Modal/Dialog.
You CAN NOT manipulate a form open ACDIALOG, because code execution stops in the calling form. This is a simple experiment you can do on your own.
 

kirkm

Registered User.
Local time
Tomorrow, 00:43
Joined
Oct 30, 2008
Messages
891
I don't quite get what's meant by 'manipulate the Form'. But yes UG the form is closed and I like to pass it a value as/before I open it. It seems Property Let cannot do that ? I was using acDialog (Isn't that the same as Open modal? I want the code block that calls the Form to wait, then continue when the Form is hidden).
as you open the form you call the function "fSetUp". Pass the information into to the custom properties, and then run the public function.
But doing this will not open the From as acDialog, will it ?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:43
Joined
May 21, 2018
Messages
3,183
No in Access. Modal, Dialog, Pop Up, and opening in ACDIALOG are not the same. See dbGuys discussion
You may be confused because I think in MSFORMS modal stops code execution and I think that is the same in VB.NET. The terminology in Access is different for the same things.

But yes UG the form is closed and I like to pass it a value as/before I open it
I am assuming you are familar with doing this in other language like VB.NET, unfortunately in VBA you cannot do that. You cannot set a value/property prior to opening/instantiating a form. In VB.NET this is common. In VBA because of these limitations Access provides OpenArgs. The only purpose of OpenArgs is to pass value/s to a form open ACDIALOG. If the form is not open ACDIALOG then you could simply set properties of the form after opening it.

I want the code block that calls the Form to wait, then continue when the Form is hidden)
Unfortunately, the only way to do this is to open ACDIALOG. In that case the limitations I discuss prevail.
Your choices
1.) If it is a simple value, past the value in using OpenArgs. All values are strings so you may have to convert. But handle the openargs in the on load event.
2) If you want to pass multiple values you can separate them with a delimiter such as value1;value2;value3 and then split them apart using the split function. Again do this In the load event
3. If it is something complicated such as passing an object, then you are limited to hard-wiring the called form. You could set a global variable before opening the form. The called form could look for global variable/s on load and set the properties itself
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:43
Joined
Jan 20, 2009
Messages
11,981
If it is something complicated such as passing an object, then you are limited to hard-wiring the called form.
A few years ago, ChrisO (RIP) demonstrated using OpenArgs to pass a pointer to an object.
 

kirkm

Registered User.
Local time
Tomorrow, 00:43
Joined
Oct 30, 2008
Messages
891
Many thanks MajP for that explanation and the link. I would have bet $$$ that modal and Dialog were the same.
Knowing the choices is a big help. Things falling into place nicely now. Cheers.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:43
Joined
Jul 9, 2003
Messages
11,633
In this case then indeed open-args does work,
To clarify, values passed through with the OpenArgs are available to the forms Load Event (I've never tested with the other events)

Information passed into the custom properties is not available to the form load event, but you can can achieve the desired result by calling your own public function "fSetUp()".

An alternative to using a custom property.
You can pass information through with a parameter in the function setup "fSetUp(intVal as integer, strVal as String, oObject as Object)".
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:43
Joined
Jul 9, 2003
Messages
11,633
You cannot set a value/property prior to opening/instantiating a form
You can set "custom properties" as I've explained. The problem is, the Form Load Event happens before the properties are set so the Form load Event can't take advantage of them. There's a simple way round that problem, just call a public function.

Another way of Passing information to a form, and have the information available for the forms load event is to pass the information into a control, for example you could have a text box on your form and pass the information into that. If you didn't want to see it, just set it's visible property to false. I call these invisible boxes "yellow perils" because to make them stand out when you are editing the form, the normal practice is to make the back colour yellow. This was one of the reasons I adopted custom properties, I just couldn't stand having "yellow perils" on my Forms.

I get the distinct impression with all of these responses, you still haven't got the answer you're looking for. I wonder if you want to recap and provide some extra information or possibly even start a new thread.

I thought, maybe you are trying to handle a menu form, if that's the case, there's some excellent information on showing/hiding menu forms in this blog here:-

 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:43
Joined
May 21, 2018
Messages
3,183
You can set "custom properties" as I've explained. The problem is, the Form Load Event happens before the properties are set so the Form load Event can't take advantage of them. There's a simple way round that problem, just call a public function.
@Uncle Gizmo
You can set custom properties but that is irrelevant to the discussion. Again the OP's whole discussion is about opening forms Dialog where code execution stops in the calling form. I know this because that is what the OP clearly states:
I want the code block that calls the Form to wait, then continue when the Form is hidden).
There is NO WAY to set custom or native properties of a form prior to opening/instantiating as I clearly stated.
You cannot set a value/property prior to opening/instantiating a form.
All you are demonstrating is opening/Instantiating a form in a non dialog mode then setting custom properties. Nothing really new to see here. This is clearly not what the OP is asking. The public function you suggest is only correcting a timing issue of the events. Again the "public function" is irrelevant because you cannot call it if opened DIALOG.

In Access there is no way to separate instantiation and opening a form and that is the problem. In other languages such as VB.NET you can instantiate the class, update properties, then open the form Modal. So you can do something like (pseudo code)
Code:
Dim frm as new formSomeForm
'the frm is now instantiated but not opened
'Now set the properties of the un-opened form
With frm
   .someProperty = "Red"
   Set .someOtherProperty = someObject
  ...
end with
'Now open the form modal
frm.openModal
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:43
Joined
Jul 9, 2003
Messages
11,633
Again the OP's whole discussion is about opening forms Dialog where code execution stops in the calling form
My interpretation of the OP's question is different to yours.

Hopefully the OP will provide the extra information I have already requested.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:43
Joined
May 21, 2018
Messages
3,183
Here is a demo using an MSFORM that shows what is being asked by the OP. The OP wants to
1. Set properties of a form before opening it
the form is closed and I like to pass it a value as/before I open it.
2. Open the form where code execution stops in the calling form and then starts again once the called form is closed.
I want the code block that calls the Form to wait, then continue when the Form is hidden).
As stated in some applications this is called "Modal", in access this is normally called "Dialog".

This cannot be done with an Access form, but it can be done in MSFORMS.

Code:
Private Sub cmdOpen_Click()
    Dim frm As MSFORM_1
    Dim clr As Long
    'Instantiate form without opening it
    Set frm = New MSFORM_1
    
    Select Case Me.FrameColor
      Case 1
        clr = vbRed
      Case 2
        clr = vbBlue
      Case 3
        clr = vbGreen
    End Select
    'set frm properties prior to instantiation
    frm.BackColor = clr
    frm.txtMessage = Me.txtMessage
    'Now open the form modal
    frm.Show
    'The following code does not execute because code execution is stopped in the previous line since form is modal
    MsgBox "The form was open modal(Access dialog); therefore code execution stopped prior to this line until the modal form is closed"
End Sub
In access there is no way to instantiate the form without opening it, here you can. With the MSFORM you can instantiate the form, set the properties, then open the form.
 

Attachments

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:43
Joined
May 21, 2018
Messages
3,183
@Galaxiom
I found the link.

Looks real interesting. I tried to get it to work, but needs to get converted to 64 bit, and I have no knowledge beyond typing PTRSafe. Have you used this? It looks so simple, I am surprised this is not commonly used.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom