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:
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
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