Setting properties in a popup form?

R

Rick Roberts

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
 
B

Brendan Reynolds

An alternative is to have the dialog form set its own properties - use the
OpenArgs argument of the OpenForm method to pass a value to the target form,
and have code in the Form_Open event procedure examine that value (retrieved
from the OpenArgs property) to determine what action should be taken ...

Select Case Me.OpenArgs
Case 1
'call code to make one set of changes
Case 2
'call code to make a different set of changes
Case 3
'call default code
End Select
 
R

Rick Roberts

Hi Brendan,

Thanks for responding. Yeah, I did think of the openargs approach and I
will likely use that in some cases, but I was wondering if there was a more
direct approach that having to parse openargs or setup globals variables or
hidden forms. In a lot of these cases I am passing data to change headings,
set rowsources, etc.

I am using Access 2003 and was hoping for better control of a form prior to
making it visible.
 

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