[AccessD] Refreshing open forms when something changes

Dan Waters df.waters at comcast.net
Mon Jun 20 10:06:17 CDT 2011


Hi John,

For a separate form, first determine if the form is open:

    If CurrentProject.AllForms("frmXX").IsLoaded = False Then

        DoCmd.OpenForm "frmXX"
        Set frm = forms("frmXX")

	 '-- Now you can do what you want with frmXX like:
        frm.Requery OR frm.Refresh
        Frm.cboList.Requery OR frm.cboList.Refresh

        '-- You can loop through the comboboxes on the form.
        For each ctl in frm.Controls
            If ctl.ControlType = acComboBox (not sure if this is correct)
            Ctl.Requery OR ctl.Refresh
        Next ctl

    End If

HTH,
Dan
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Monday, June 20, 2011 9:12 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] Refreshing open forms when something changes

Have you ever needed to refresh queries, lists or the form itself when
something happens on another form entirely?  How do you do this?

I have a form where a user can open a volunteer form and select cities that
(s)he wants to see meetings in.  Selecting cities in a subform on that
volunteer form causes two lists up in the volunteer form to requery.  It may
also affect combos in subforms on an already open frmInmate and so those
combos need to requery.

Being a class sort of guy, my solution is to have a message class.  The
message class can raise an event.  The message class emulates an email with
a From, To, Subject and body.

So I set up a global pointer to an instance of the message class which is
initialized when the program starts.  Now a message "channel" is available
for any process to send a message.  Processes that want to send a message
basically calls a method
	
cmsg.Send "MyName", "WhoThisIsGoingTo", "MySubject"

The form which needs to receive the message dimensions a message class
withevents and sinks the Send event.

private withevents mcMsg as dclsMsg

In the Load of the form it grabs a pointer to the global message class so it
can sink the events.

private sub Form_Open(Cancel as Integer)
	set mcMsg = cmsg()
end sub

And now sinks the event and does something with it:


private sub mcMsg_Message(varFrom as variant, varTo as variant, varSubject
as variant, varMsg as
variant)

	if VarFrom = "MyName" then
		if VarTo = "WhoThisIsGoingTo" then
			if VarSubject = "MySubject" then
				'Requery the combo
				MyCombo.requery
			endif
		endif
	endif
end sub

The reason for doing all of this is that if the form is open it requeries
the combos, if it is not nothing happens (in this form).  Any and all forms
which need to requery something can subscribe to this event (message) and
requery whatever each form needs to requery when the list of cities changes.

I have discussed the message class previously but I will email the class in
a couple of hours.

--
John W. Colby
www.ColbyConsulting.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list