Close popup form from a continuous subform

0

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.
 
M

Marshall Barton

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?

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

An alternative could be to park the name in a module level
variable so you can retrieve it when another event is
selected.
 
0

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
selected.

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
 
M

Marshall Barton

Unfortunately, they don't follow a convention that would lend itself
to looping.


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


Not unless your code project is corrupted and all logic is
out the window. Before leaping to that conclusion, you
should use some breakpoints and watch variables to do some
deep debugging. What you posted here makes sense and I
don;t see how it can do what you are seeing. I suspect
there is some logic flaw that is changing the name stored in
ActivePopUpForm or the lookup is retrieving the wrong form
name.
 
0

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!
PatientID
rstTemp.Close
Exit Sub

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

Marshall Barton

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!
PatientID
rstTemp.Close
Exit Sub

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


No. Assuming the recordset is opened in the same click
event procedure, it would go out of scope anyway.

So far, all the code snippits you've posted look fine.
You said that sometimes the wrong form is opened, so I would
concentrate on the code that looks up the form and use watch
variables and breakpoints to analyze any repeatable scenario
with the problem. If the problem does not appear to be
repeatable, try to pin it down to a specific sequence of
your "events".
 
0

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
record.
 

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