Setting focus back onto subform

carlton123

Registered User.
Local time
Today, 07:55
Joined
Mar 18, 2011
Messages
48
I have a form with a tab control on with a subform on that. When in the subform i press a command button which opens another form which puts information from subform to new form. when i close the form i want the focus to go back onto the subform in the same row as before is this possible any help would be very welcome im new to this only done excel before thanks

ps its just the focus on that row in subform i need help with
 
What information are you sending to the form being opened and how are you doing this?
 
In the Unload event of the form that opens put this:
Code:
Forms("[COLOR=Red]Name of form here[/COLOR]").Controls("[COLOR=Red]Name of first control here[/COLOR]").SetFocus
Put the right form name and control name in the code. That is the form and control you would like to get focus.
 
I posted this reply 2 hours ago – it must have disappeared into cyberspace.
Sounds like you already know how to get the focus back to that subform.
To get to a specific row on that subform, you can use FindFirst.
First you need to save the ID of that original record on the subform. Easy way is to save that ID on a hidden form (if you don't already have one, make a hidden form that stays open hidden while the app is open).
Code to retrieve the saved primary key and use it:
Dim lngID as Long
lngID = Forms![HiddenFormName].txtID 'txtID – name of textbox that saves 'the value for the primary key that you want to return to.
With Me.RecordsetClone
.FindFirst "[PrimaryKey] = " & lngID
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With

Note: replace my object names with yours.
 
The attached Sample demonstrates how to search for and select a record on a Subform from a pop up form, it should give you some pointers.
 

Attachments

Oops... that should have been -->
Code:
Forms("[COLOR=Red]Form Name[/COLOR]").Controls("[COLOR=Red]Subform Control Name[/COLOR]").Form.Controls("[COLOR=Red]Control Name[/COLOR]").SetFocus
The button that's pressed is on the subform and I would imagine it's placed in the Detail section. When the focus leaves the form the button would be the last control that had focus on that particular record. All that needs to be done is to set focus to the control and it will remain on the record you were previously on and move to the control.

Still Unload event by the way :)
 
thanks for all replieswhat i was doing was correct it was just the way i was closing the other form when i used DoCmd.Close everyhting worked fine thank you all
 
Out of curiosity, what did you already have that was working?
 

Users who are viewing this thread

Back
Top Bottom