Can you check a show modal property

J

jc

If you hit F1 on the ShowModal property in the Property box of a user form it
says it is read only.

In Sub UserForm_Activate the code:

If Me.ShowModal = False Then
MsgBox "Modeless"
End If

Causes Compile Error: Method ro data member not found

Is there code that can be used to check if a UserForm is Modal or Modeless?
 
D

dan dungan

Hi JC

I don't know, but now I'm curious.

I think to test for modeless, the form would have to be loaded.

But it seems that your code would determine how to load the form; so,
I don't understand how you wouldn't know if the form was modeless or
modal.

How would you use such a function if it were to exist?

Dan
 
J

jc

I want to use the same form in a case where I want to use it modal and
another case modeless. So when I instanciate it, the Userform_Initialize
procedure can test if modal or modeless and make some adjustments based on
this.
 
G

Gary Keramidas

just load it anyway you want

Sub test()
UserForm1.Show vbModal
End Sub

Sub test2()
UserForm1.Show vbModeless
End Sub
 
J

jc

I don't think you read my previous post close enough. I want to modify the
form when I use it modal so in initiation I need to check what type of show
it is.
 
D

Dave Peterson

Maybe you can add a public variable and make sure you change it before you show
the userform. Then check that variable's value when you need to.

Public UserFormMode as long

Sub test()
userformmode = vbmodal
UserForm1.Show userformmode
End Sub
Sub test2()
userformmode = vbmodeless
UserForm1.Show userformmode
End Sub

Then in your code...

if userformmode = vbmodal then
...
 
J

jc

That would get the job done.
Thanks
--
CroceJC


Dave Peterson said:
Maybe you can add a public variable and make sure you change it before you show
the userform. Then check that variable's value when you need to.

Public UserFormMode as long

Sub test()
userformmode = vbmodal
UserForm1.Show userformmode
End Sub
Sub test2()
userformmode = vbmodeless
UserForm1.Show userformmode
End Sub

Then in your code...

if userformmode = vbmodal then
...
 

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