Close popup form from a continuous subform


0 1

I have a continuous subform (fsubEvents) that lists various patient
events that have been entered for each patient (a well-check visit, a
lab test, etc.).

When you click on an event, OnClick code opens a pop-up form showing
that event's information. When the user selects a different event from
the continuous subform, I'd like to close the currently open event
form (if there is one), and open the next relevant form.

Because each type of event has its own form, it's difficult to know
which form may have just been opened, so this won't work:

If IsLoaded("PopUpFormName") = True Then
DoCmd.Close acForm, "PopUpFormName"
End If

.... unless there's a way to find the name of the currently open popup
form and pass that to the IsLoaded argument. Or is there a better way
to address this?

Thank you for any suggestions.

0 1

If your popup forms follow a distinctive naming convention,
you could loop through the Forms collection checking if one
(or more) are open.

Unfortunately, they don't follow a convention that would lend itself
to looping.
An alternative could be to park the name in a module level
variable so you can retrieve it when another event is

Hmm ... The subform's OnClick code that opens the pop up form in the
first place has to find the name of the form (it looks up the form
name in a table based on a hidden value on the subform). It assigns
it to stDocName (stDocName = rstTemp("EventFrm") and uses it like so:

DoCmd.openForm stDocName, , , stLinkCriteria

So I added this line after it:

ActivePopUpForm = stDocName

.... then put this at the top of the form's module area:

Dim ActivePopUpForm As String

.... and added this to the start of the OnClick code:

If IsLoaded(ActivePopUpForm) = True Then
DoCmd.Close acForm, ActivePopUpForm
End If

It works most of the time. It fails, I think, when I a patient has
several of the same type events(e.g., a Well Check visit on 1/2/2010
and one on 5/3/2012). After clicking on the second instance, things
get screwy and sometimes an earlier assigned form is opened. That
suggests that ActivePopUpForm is sometimes being assigned to
stDocName, when I always want to be the other way around.

Could it be a problem with this line?:

ActivePopUpForm = stDocName

0 1

This is the code that follows stDocName = rstTemp("EventFrm") :

stLinkCriteria = "[EventID]=" & rstTemp![EventID]
DoCmd.openForm stDocName, , , stLinkCriteria
ActivePopUpForm = stDocName
Forms(stDocName).Controls("PatientID").Value = Me.Parent!
Exit Sub

Notice the rstTemp.Close. Could that be the culprit?

0 1

Figured this out. One of my event forms had a requery line in the
AfterUpdate event, which ran while the recordset was still being
manipulated. It was requerying the continuous subform. This moved it
to the first record, and since my forms opened based on the record
(and form category) criteria, it was opening a form for the first

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