WithEvents Form AccessObject ... conundrum

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
2,114
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hello all.
My goal at the moment is: To open Form1 as background, make it translucent, then use the openArgs to pass a name to open Form2 on top of it. When Form2 is closed Form1 to close automatically.
I achieved it easily with DoCmd.OpenForm but then I have to set WindowMode:=acDialog, which shows the form titlebar and ruins the design.
So I am trying to make it in another way. After some time I got to the idea to declare (in the module of Form1) a form object withEvents, assign Form2 to it, open it and when it is closed it will close Form1.
So far the problem is:
Case 1: I get a Type mismatch error on the line Set frm = ....
VBA Code:
Private WithEvents frm As Access.Form
...
Set frm = CurrentProject.AllForms(Me.OpenArgs)
frm.Close = "[Event Procedure]"
DoCmd.OpenForm frm.Name
...
Case 2: When I try this - The compiler just says Compile error: Object does not source automation events
VBA Code:
Private WithEvents frm As AccessObject
It does not accept Variant or Object at all on this line.

Any workarounds, or better ideas than mine are welcome?
Thanks in advance.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Not sure I get all of this. AFAIK, there is no such thing as a translucent form property. If there is, I'd sure like to learn how to do that. Maybe you mean invisible?
Second, you can open a form as popup and/or modal - no need to use acDialog. You need to ensure other properties are set in harmony in order to not not show a title bar. I think those are no control box, open as popup, maybe no close button, and a single space in the form caption should prevent the little form icon.
Next, if you want to assign a property on the fly (if that's what frm.Close = "[Event Procedure]" is) then it's usually like = "=[Event Procedure]" assuming that is the name of the function - which by thy way, it has to be a function.

Maybe I don't understand all of what you're doing. I don't see why you can't just command form1 to close in form2 close event rather than declaring forms as objects and such.
 
Upvote 0
Not sure I get all of this. AFAIK, there is no such thing as a translucent form property. If there is, I'd sure like to learn how to do that. Maybe you mean invisible?
Second, you can open a form as popup and/or modal - no need to use acDialog. You need to ensure other properties are set in harmony in order to not not show a title bar. I think those are no control box, open as popup, maybe no close button, and a single space in the form caption should prevent the little form icon.
Next, if you want to assign a property on the fly (if that's what frm.Close = "[Event Procedure]" is) then it's usually like = "=[Event Procedure]" assuming that is the name of the function - which by thy way, it has to be a function.

Maybe I don't understand all of what you're doing. I don't see why you can't just command form1 to close in form2 close event rather than declaring forms as objects and such.
Well, I can't really explain everything but i will try to clarify:
Threre isn't a Translucent property but with some APIs from an Excel file (found some time ago on the net) and some adjustments for access it actually works pretty well. When used with combination with message box it's quite good.
I need to use acDialog to make the code in the caller Form1 to wait for Form2 to be closed. Then Form two shows as a dialog (with title bar - because of acDailog), but Form2 has no border by design - so I don't like it.
This is why I want to use a form object with Events and to use the close event on form2 to tell the code in Form1 that it can continue. That's what the following is supposed to be doing (in Form1):
VBA Code:
Private WithEvents frm As Access.Form
...
Private Sub Form_Open(Cancel As Integer)
...
                Set frm = CurrentProject.AllForms(Me.OpenArgs)
                frm.Close = "[Event Procedure]"
                DoCmd.OpenForm frm.Name
...
End Sub
...
Private Sub frm_Close()
    Set frm = Nothing
    DoCmd.Close acForm, Me.Name, acSaveYes
End Sub
...
But it seems I cannot do it in this way. Actually the ultimate question for me here is: How to assign a closed form to a Form Object variable WithEvents?
 
Upvote 0
I think I may have just come up with a working Idea, but will test it later on and share the result. Basically the idea is to use a second object (w/o events) to open the form, then assign the opened form to a form object with events. Something like this:
VBA Code:
Private WithEvents frm As Access.Form
Private obj
...
Private Sub Form_Open(Cancel As Integer)
...
                Set obj = CurrentProject.AllForms(Me.OpenArgs)
                DoCmd.OpenForm obj.Name
                Set frm = Forms(obj.Name)
                frm.Close = "[Event Procedure]"
...
End Sub
...
I already feel positive about it but will test it later and share the result.
 
Upvote 0
Solution
:sick: the above one works almost well with one exception: Form2 remains behind Form1. ?
Any clues anyone?
...
Just checked - If I make form2 Modal, then it works as I want it to.
 
Upvote 0
I guess you figured out that you don't need acDialog before I had a chance to counter your claim, which in fairness, I had already mentioned.
Second, you can open a form as popup and/or modal - no need to use acDialog
Glad to see you got it working, although I still think you've over complicated it - unless you need to do what you're doing because of this translucent thing, which I'm none the wiser about.
 
Upvote 0
Glad to see you got it working, although I still think you've over complicated it
So am I, thank you, although it seems I have a tendency to do this ocasionally.:biggrin:
The translucent part is just a design feature, which turned out to be the less complicated part. I just wanted to achieve somthing similar to UAC prompts in Windows.
Second, you can open a form as popup and/or modal - no need to use acDialog
Just to explain something for whoever else reads this - the above statement is generally incorrect. Depending on the situation you can use one or the other, but there is a substantial difference between the two.
- The PopUp form property just brings the form on top, Modal - simply forbids you access to the forms behind it. But the code, the one that called the form, keeps on executing.
- When you open a form as acDialog, the form acts as a MsgBox or InputBox - the code that called it is waiting for the form to close before resuming its execution.
 
Upvote 0
You are correct; I remembered it wrong. It is the acDialog call that suspends code and not the modal/popup property combination. Is this the sort of look you are after?
NoTitlebar.jpg

You might say the white space above is the title bar, but you can't see any close button, form icon or form caption.
 
Upvote 0
Well, I meant with respect to the title bar. Take away the navigation control and record selectors and you have the same thing but no sort of transparency.
Did you get your code to work? I found some but it made no difference in Access. There were some cautions about using API's for this sort of thing.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,138
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top