By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Selecting forms with multiple instances

P: n/a
I'm blanking out on this one.

In an old applicaiton, I am implementing a new feature to allow the
user to open multiple instances of a main form. I've got that
working, using the code for this from the Access Developers Handbook
(which I've used successfully many times in the past).

Now, the problem I'm having is that when I close the second
instance, the focus is not necessarily going back to the original
form.

DoCmd.SelectObject can't work because it requires a form name and
all forms have the same name, of course.

Is there a way to select a form by index? I do know the index in the
form's collection, because I'm storing it in a global variable for
the original form.

Any ideas?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Take a look at what Allen Browne has at
http://www.allenbrowne.com/ser-35.html

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.74...
I'm blanking out on this one.

In an old applicaiton, I am implementing a new feature to allow the
user to open multiple instances of a main form. I've got that
working, using the code for this from the Access Developers Handbook
(which I've used successfully many times in the past).

Now, the problem I'm having is that when I close the second
instance, the focus is not necessarily going back to the original
form.

DoCmd.SelectObject can't work because it requires a form name and
all forms have the same name, of course.

Is there a way to select a form by index? I do know the index in the
form's collection, because I'm storing it in a global variable for
the original form.

Any ideas?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Nov 13 '05 #2

P: n/a
Yes, we suggest using the form's hWnd as the index of the collection.

You can then loop through the Forms collection, and find the instance that
has the hWnd, and then Forms(i).SetFocus

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:YI********************@rogers.com...
Take a look at what Allen Browne has at
http://www.allenbrowne.com/ser-35.html

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.74...
I'm blanking out on this one.

In an old applicaiton, I am implementing a new feature to allow the
user to open multiple instances of a main form. I've got that
working, using the code for this from the Access Developers Handbook
(which I've used successfully many times in the past).

Now, the problem I'm having is that when I close the second
instance, the focus is not necessarily going back to the original
form.

DoCmd.SelectObject can't work because it requires a form name and
all forms have the same name, of course.

Is there a way to select a form by index? I do know the index in the
form's collection, because I'm storing it in a global variable for
the original form.

Any ideas?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Nov 13 '05 #3

P: n/a
Dim aForms(1 To 10) As [Form_MDAC and ESO]

Sub CreateInstances()
Dim z As Long
For z = LBound(aForms) To UBound(aForms)
Set aForms(z) = New [Form_MDAC and ESO]
aForms(z).Caption = aForms(z).Caption & "_" & z
aForms(z).Visible = True
Next z
DoCmd.RunCommand acCmdWindowCascade
End Sub

Sub RemoveInstances()
Erase aForms
End Sub

Nov 13 '05 #4

P: n/a
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in
news:YI********************@rogers.com:
Take a look at what Allen Browne has at
http://www.allenbrowne.com/ser-35.html


That just duplicates the same code as in ADH, though it's simpler
and more clearly presented!

I later determined that the problem was that I wasn't cleaning up
the collection, because of an incomplete implementation of the code
copied from the last app where I used it. I got tired and gave up
before solving it, but at least know where my problem is.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #5

P: n/a
"ly******@yahoo.ca" <ly******@yahoo.ca> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
Dim aForms(1 To 10) As [Form_MDAC and ESO]

Sub CreateInstances()
Dim z As Long
For z = LBound(aForms) To UBound(aForms)
Set aForms(z) = New [Form_MDAC and ESO]
aForms(z).Caption = aForms(z).Caption & "_" & z
aForms(z).Visible = True
Next z
DoCmd.RunCommand acCmdWindowCascade
End Sub

Sub RemoveInstances()
Erase aForms
End Sub


Did anyone actually read my question before answering with things I
was already doing?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.