Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Modal / Dialog form as object with VBA code.

Status
Not open for further replies.

fordboy0

Programmer
Jan 24, 2003
13
US
Hey all,

I have an interesting problem. I had posted earlier about making "Message Boxes" non-centered. It's for an app that's on dual monitors, and well, a message box split between two monitors sucks. I got some great responses about creating a modal form with borderstyle set to dialog. I was cruising along well until...

This is a fairly large app with tons of message boxes. Since I will be using my form "frmOkYesNo" for multiple things, I thought it would be simple to add class functionality via property let and property get functions and call it as such:

[tt]dim MyDialog as New form_frmOkYesNo

MyDialog.modal=true
MyDialog.visible=true

select case MyDialog.reply '
...
end case
[/tt]

The problem is that even if I set the design-time properties (BorderStyle as Dialog, popup, and modal), the form doesn't stop program execution and of course, it closes once the calling procedure destroys the object.

Short of doing this: (Not pretty but it DOES work)

[tt]do while isnull(MyDialog.reply)
DoEvents
loop
[/tt]

I can't figure out why it doesn't work as expected. I don't want to create a different form for each type of dialog that I want, nor do I want to pass arguments via form.openargs. I realize that docmd.openform MyForm,,,,ACDialog (forgive me if there are too many commas -lol) solves my Dialog problem, but it leaves me with a much less flexible solution.

Any thoughts? Following is the code I'm using in the form. It's not entirely complete, but unless I can get this little part working it's moot anyway.

Thanks!
Jeff

[tt]'Form frmOkYesNo
Option Compare Database

Private m_YesCaption As String
Private m_NoCaption As String
Private m_OkCaption As String
Private m_BodyText As String
Private m_FormCaption As String
Private m_Reply As Integer
Private m_FormType As Integer

Public Enum FormTypeConstants
OKDialog = 1
YesNoDialog = 2
ErrorDialog = 3
End Enum

Public Property Let YesCaption(NewValue As String)
m_YesCaption = NewValue
End Property

Public Property Let NoCaption(NewValue As String)
m_NoCaption = NewValue
End Property

Public Property Let OkCaption(NewValue As String)
m_OkCaption = NewValue
End Property

Public Property Let FormCaption(NewValue As String)
m_FormCaption = NewValue
End Property

Public Property Let BodyText(NewValue As String)
m_BodyText = NewValue
End Property

Public Property Get Reply()
Reply = m_Reply
End Property

Public Property Let FormType(NewValue As FormTypeConstants)
m_FormType = NewValue
End Property

Public Sub SetUpDialog()
If Not IsNull(m_YesCaption) Then btnYes.Caption = m_YesCaption
If Not IsNull(m_NoCaption) Then btnNo.Caption = m_NoCaption
If Not IsNull(m_OkCaption) Then btnOK.Caption = m_OkCaption
If Not IsNull(m_FormCaption) Then Me.Caption = m_FormCaption
If Not IsNull(m_BodyText) Then lblText.Caption = m_BodyText

' Select Case m_FormType
'
' Case OKDialog
' btnNo.Visible = False
' btnYes.Visible = False
' btnOK.Visible = True
'
' Case YesNoDialog
' btnNo.Visible = True
' btnYes.Visible = True
' btnOK.Visible = False
'
' Case ErrorDialog
' btnNo.Visible = False
' btnYes.Visible = False
' btnOK.Visible = OK
' Me.FormCaption = "ERROR!"

' End Select

End Sub

Private Sub btnNo_Click()
m_Reply = vbNo
End Sub

Private Sub btnOk_Click()
m_Reply = vbOK
End Sub

Private Sub btnYes_Click()
m_Reply = vbYes
End Sub
[/tt]
 
The trick here is to open the form in acDialog mode (as opposed to making visible). e.g.

Code:
docmd.openform "frmOkYesNo",,,,,,acDialog

select case frmOkYesNo.Reply
...
...
end select

 
Another way would be to use public variables in a module that are set by the diaog box on whatever event you like. iirc. You can then reference the variables when you like.

hth

Ben ----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
The trick here is to open the form in acDialog mode (as opposed to making visible). e.g.

docmd.openform "frmOkYesNo",,,,,,acDialog

select case frmOkYesNo.Reply
...
...
end select


Yes, but unfortunately, this restricts the level of customization once again... If I open the form like [tt]"docmd.openform "frmOkYesNo",,,,,,acDialog"[/tt], I have no way to set the exposed properties / methods of the class. ie. The code stops while the form is loaded.

I need to be able to show the form object that I've created in code AND make it modal. VB allows this like:

[tt]dim MyDialog as new form_frmOkYesNo

MyDialog.Modal=True
MyDialog.Show <-- This is what VBA-Access doesn't seem to have
[/tt]

Perhaps there is a way to open the object that I've created with the docmd command?

-Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top