Docmd.GoToRecord gets mixed up between two instances of the same form

JMA92410

New member
Local time
Tomorrow, 00:20
Joined
Apr 19, 2019
Messages
4
Hello folks !
I have a form which may have several instances
I have found all necessary explanations on Internet how to do that and it works (basic explanations at the end of this post)
On the form I have buttons that enable going to previous or next record. I need these because for each record I have related data displayed on a treeview on the form and I have code to update the treeview.
These buttons basically do this :
Code:
Docmd.GoToRecord acForm, Me.Name
Now here is what happens :
I open a first instance of the form : Form1
I open a second instance of the form : Form2
on Form2 I click on the button to go to next record, and it is Form1 that moves to its next record.
I have tried putting this before the Docmd instruction :
Code:
Me.SetFocus
This does not solve the issue.
The problem with Docmd is that it takes the form name as parameter, and all instances of the form have the same name (I have tried setting a specific name for each instance, but it is a read only property. Hard luck !)
Do you have any idea what can be done ?
Thank you !
Jean-Marie

PS How I create my forms : This is the code inside a specific class module (I have declared a global variable of that class) :
Code:
Set objForm = New My_Form
MyFormsCollection.add Cstr(objForm.HWND), objForm
(Adding the objForm to a remanent collection keeps the form alive)
 
Post was moderated. Now approved.
This post is to trigger email notifications
 
From your description this is a very convoluted approach.
I've not tried anything like this so can't suggest the answer offhand.

But why do you need several instances of the same form?
Why can't you just move the same instance of the form onto the next record?
 
Moving to different form instances to same record.

Code:
myFormsCollection(1).recordset.FindFirst "SomeField = " & someValue
myFormsCollection(2).recordset.FindFirst "SomeField = " & someValue
 
If you use FindFirst as MajP has stated the they act separately, without having to reference a form by name/ID/Hwnd.?

I've just downloaded Allen Brownes Multiple Instance DB and set breakpoint on a button and amended the value to find and all have different seperate records.?

http://allenbrowne.com/ser-35.html

HTH
 
isladogs : there are cases where I need two instances of the same form to be displayed concurrently, but it would be a little complicated to explain (I would have to go into my data model)
MajP and Gasman : thank you for your ideas. I eventually found a code which works. For the button which makes the form go forward, instead of :
Code:
DoCmd.GoToRecord , Me.Name, acNext
I have now :
Code:
If Not Me.Recordset.EOF Then Me.Recordset.MoveNext
and it works fine !
 

Users who are viewing this thread

Back
Top Bottom