Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setfocus from subform to another subform (IsLoaded?)

Status
Not open for further replies.
Oct 6, 2000
7
US
In Access2000 I have a subform used by two different main forms. On the exit event of one of the subforms fields I want to setfocus on a field on the open main form, so that the user doesn't get stuck tabbing inside the subform. How can VBA determine which of two main forms is open so that I can set focus to a field on whichever main form is open? Or if there is another way to end the tabbing loop that would be helpful too. I tried referencing the IsLoaded property of one of the main forms to check if it was open, but lacking any examples I couldn't make the code work. [sig][/sig]
 
Hi,
Try looping through the forms collection with a For Each loop. ie

Dim frmCurrent as Form, blnIsOpen1 as Boolean, _
blnIsOpen2 as Boolean

blnIsOpen1 = False
blnIsOpen2 = False

For Each frmCurrent in Forms
If (frmCurrent.Name = "frmMyForm1") Then
blnIsOpen1 = True
ElseIf (frmCurrent.Name = "frmMyForm2")
blnIsOpen2 = True
End If
Next

If (blnIsOpen1) then
.... 'set focus code
ElseIf (blnIsOpen2)
.... 'set focus code
End If

Sloppy but you get the idea.
CCTC1
Rob Marriott
rob@career-connections.net [sig][/sig]
 
I got the answer on a related forum. Here is my application of the best answer which was simply Me.Parent.Name

Private Sub ScheduledDate_Exit(Cancel As Integer)
Dim myparent As String
myparent = Me.Parent.Name
If myparent = "frmProposals" Then
Form_frmProposals.sbfrmProposalDetails.SetFocus
Else: Form_frmAlliantProposal.sbfAlliantProposalDetails.SetFocus
End If
End Sub [sig][/sig]
 
You're right, that is a much more efficient way of finding the name of the parent form. [sig][/sig]
 
You can also refer to 'lngID = me.parent.parent!ID' aswell. I found it out yesterday from a mistype which had me looking at the ID number 2 levels up from the form I was running the code from instead of 1. But very usefull (when used intentionally).

Did you know that you can leave a subform control Unbound and then make its ControlSource = strFormName. If the form indicated to by strFormName is correctly coded using me.parent properly you can then display different subforms in the same control.

I have also then managed to create a range of subforms each with a public function called SelectItem().

The Parent form then calls this function. The advantage here is I have a std main form but different fields displayed in the subform and a select routine unique to each.



[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top