G
Guest
Has anyone found a way to open and modify a pop-up form’s properties before
it is displayed?
If you open a form using acDialog Windowmode value it opens the form as a
popup, halts the running code in the calling module, and it blocks the user
from any other Access User Interface. All well and good. But I need to
alter the form's properties before the form is displayed. The problem is you
can’t open a form invisibly, alter some properties and then display it in
such a way that the calling module code will stop running and wait for the
return from the popup.
As a workaround I have used extensively the idea of opening the form
invisibly (not using acDialog mode), setting the new forms properties,
display the form and then put myself into a counter loop (with a doevents)
constantly checking if the pop up is still open/visible. Once it’s invisible
I can retrieve properties from the popup and move on.
This works fine but is CPU intensive! 100% until the popup is no longer
visible. On a workstation it’s not usually an issue but on a notebook I put
the CPU fan into overdrive. I understand that this is a huge difference
between Access and Visual Basic.
Any ideas? Global variables could be used I guess but that seems messy as I
have a lot of popup forms!
Below is an example of the routines I am using.
Open popup forn
Dim frm As Form_Window_ContactAdd
Set frm = New Form_Window_ContactAdd
frm.LetProperty_AccountId = PassAccountId
If ShowFormAndWait(frm) Then
' Upon return and close the form
AddedNewContact = frm.GetProperty_AddedNewContact
DoCmd.Close acForm, "Window_ContactAdd"
End If
Set frm = Nothing
Public Function ShowFormAndWait(frm As Form) As Boolean
Dim lngLoop As Long
Const adhcInterval As Long = 1000
ShowFormAndWait = False
frm.Visible = True
Do
If lngLoop Mod adhcInterval Then
DoEvents
' Is it still visible?
If Not frm.Visible Then
ShowFormAndWait = True
Exit Do
End If
lngLoop = 0
End If
lngLoop = lngLoop + 1
Loop
End Function
it is displayed?
If you open a form using acDialog Windowmode value it opens the form as a
popup, halts the running code in the calling module, and it blocks the user
from any other Access User Interface. All well and good. But I need to
alter the form's properties before the form is displayed. The problem is you
can’t open a form invisibly, alter some properties and then display it in
such a way that the calling module code will stop running and wait for the
return from the popup.
As a workaround I have used extensively the idea of opening the form
invisibly (not using acDialog mode), setting the new forms properties,
display the form and then put myself into a counter loop (with a doevents)
constantly checking if the pop up is still open/visible. Once it’s invisible
I can retrieve properties from the popup and move on.
This works fine but is CPU intensive! 100% until the popup is no longer
visible. On a workstation it’s not usually an issue but on a notebook I put
the CPU fan into overdrive. I understand that this is a huge difference
between Access and Visual Basic.
Any ideas? Global variables could be used I guess but that seems messy as I
have a lot of popup forms!
Below is an example of the routines I am using.
Open popup forn
Dim frm As Form_Window_ContactAdd
Set frm = New Form_Window_ContactAdd
frm.LetProperty_AccountId = PassAccountId
If ShowFormAndWait(frm) Then
' Upon return and close the form
AddedNewContact = frm.GetProperty_AddedNewContact
DoCmd.Close acForm, "Window_ContactAdd"
End If
Set frm = Nothing
Public Function ShowFormAndWait(frm As Form) As Boolean
Dim lngLoop As Long
Const adhcInterval As Long = 1000
ShowFormAndWait = False
frm.Visible = True
Do
If lngLoop Mod adhcInterval Then
DoEvents
' Is it still visible?
If Not frm.Visible Then
ShowFormAndWait = True
Exit Do
End If
lngLoop = 0
End If
lngLoop = lngLoop + 1
Loop
End Function