Setting Focus to Non Default Instance of a Form

Fran Lombard

Registered User.
Local time
Today, 08:53
Joined
Mar 12, 2014
Messages
132
I can't figure out how to set focus to a non Default instance of a form.

Environment
A2007 ADP Project
Document Window Option - Tabbed Documents
MS SQL 2012 Express DB
Windows 7 64 Bit

I using Allen Browne's method to open more that one version of form, storing each form object in a collection declared in a module. No problem there.
Now I'm trying to add a command button on an form to set focus to one of these non-default instances already open.

The form I am trying to set focus to has a the following related properties
Default View: Split Form
Pop-up: No
Modal: No

The form that has the command button on it is of the same type.

Here is the code I've tried:

Code:
'Code on Calling Form
Private Sub cmdProjectList_Click()
Dim FunctionResult As Boolean
        
        If AppForms.GoToForm("ProjectList") = False Then
            AppForms.Load_ProjectList
        End If
        
End Sub


'Code in Module  AppForms

Public Function GoToForm(ByVal FormName As String) As Boolean
On Error GoTo FunctionError
Dim i As Long
Dim cnt As Long

    If Not CurrentProject.AllForms(FormName).IsLoaded Then
        GoToForm = False
        Exit Function
    Else
        cnt = Forms.Count
        For i = 0 To cnt - 1
             'Debug.Print Forms(i).name
            
            If Forms(i).name = FormName Then
                Forms(i).SetFocus
               ' CurrentProject.AllForms.item(FormName).Properties.Application.Forms.item(i).SetFocus
                Exit For
            End If
        Next i
    End If

GoToForm = True
FunctionExit:
    Exit Function
    
FunctionError:
    GoToForm = False
    MsgBox "Error No: " & Err.Number & " - " & Err.Description, vbOKOnly
    Resume FunctionExit

End Function

The code compiles and executes with seemingly no problems.
It finds the form loaded, then cycles though and finds the form in Forms but the SetFocus call seems to do nothing. When I run the code against a defualt instance ( one not opened using Allen Browne's method) it works fine and sets focus to it as expected. Any help or ideas as to what I should try would be greatly appreciated.

Thanx
Fran
 
Can you post a db that causes this problem that we can test? I am interested in this problem, but I don't have time to write a Db to test this right now.
 
The instance of the object would need to be identified by a variable name or by the index name in the collection.

Run the SetFocus method of that object.
 
I've attached a db with the identified behavior
It seems the real problem is difficulty Setting Focus to forms with the Default View of:Split Forms.

The code to works fine for forms with the Default View of: Single Form

On the Projects List screen there are 2 command buttons Contract Definition and Contract List that call the code in question.

The Function being being used is in the AppForms module: GoToForm

The code in question works fine for Contract Definition but does not behave as expected for Contract List. Based on what I'm seeing I would say there is a bug in Access related to setting focus to Split Forms.
 

Attachments

Galaxiom - Thanks for the reply

I have tried setting focus to the object - you'll notice in the code I posted I'm iterating through the forms collection and using the index value when setting focus.

Additionally I tried declaring a variable as form setting it to the object in the forms collection using the index then setting focus to that variable. In all scenarios same result.

Works fine for Single Form forms but not for Split Form forms.
I've just attached a sample db if you care to take a look.

Thanks again.
Fran
 
Works fine for Single Form forms but not for Split Form forms.

Split forms do not properly expose their object model. They should be avoided completely, especially when automating. There are many other aspects of their model that are unsupported.

Really they are just a beginner's tool.

Build your forms as subforms.
 
So I took a look at this system, and my observation is that I wouldn't do it. A non-default instance is a specialized tool, and a split form is a generalized tool, so the approaches don't seem to me to work together. And to have these full-page, multiple instances of lists is just confusing/overwhelming.

Use non-default instances where you have a complex single record/subform that might take time to fill out, for instance, maybe you have multiple orders that you must work on at the same time, and a customer calls to check on his order and so you need to open another one, and not lose your "in work" data on other instances. Then you want non-default instances, and then you want a search tool to find a form BY CURRENT DATA, as well as by name. Then you want non-default instances.

So, maybe it's a bug, maybe not, but this doesn't look like an implementation of this feature that provides an advantage, even if you could make it work. I know that's a bit of an unsatisfying answer, but it's what I think about this.

Hope this helps,
 
Thanx for your observations and time.
I'll move past this issue and live with the limitation.
Fran
 
Galaxiom - Thanks for the reply

I have tried setting focus to the object - you'll notice in the code I posted I'm iterating through the forms collection and using the index value when setting focus.

I think you completely missed the point about the collection. The Forms Collection is next to useless when addressing multiple instances becaue they cannot be separately identified. Your code would only ever find the first instance.

Allen Browne explains an excellent way to manage multiple instances so that they have separate named indexes.

http://allenbrowne.com/ser-35.html
 
Thanx - I will check out the link.
Btw - Finding the first instance of the form was the intended functionality.
I think I introduced some confusion on this issue by bringing up the multiple instances of the form in the first place. I had mistakenly attributed the issue to the fact that I was opening the form using Allen Brownies method when in the end the issue stemmed from trying to set focus to a split form. I came across a post on another site where this same issue was confirmed. Now off to re-write some 50 or so screens oh joy! How do I mark this as solved:)
 

Users who are viewing this thread

Back
Top Bottom