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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Focus/Go to Textbox on subform from subform

Status
Not open for further replies.

spartansFC

Programmer
Apr 1, 2009
165
GB
Hi

This tiny little problem which is probably so easy to solve is getting on my nerves.

I have a form which is made up of 2 other subforms:

frmParentChildReviewDates
frmParentChildReviewDatesSubform
frmParentChildReviewDatesSubformInformation

What i'm trying to do is stop the user from entering data on the frmParentChildReviewDatesSubformInformation before they enter anything on the frmParentChildReviewDatesSubform. I want it to go back to dteReviewDate which is a textbox on frmParentChildReviewDatesSubform.

So on the before update event on the lngRevuewDateInformation textbox on frmParentChildReviewDatesSubformInformation, i have the following code:

Code:
Private Sub lngRevuewDateInformation_BeforeUpdate(Cancel As Integer)
If IsNull(Forms!frmParentChildReviewDates![frmParentChildReviewDatesSubform].Form![dteReviewDate]) Then
        MsgBox "You must enter a Review Date, please go back and enter date to continue"
        'DoCmd.GoToControl "forms!frmParentChildReviewDates![frmParentChildReviewDatesSubform].[dteReviewDate]"
        'DoCmd.GoToControl "[frmParentChildReviewDatesSubform]![dteReviewDate]"
        'frmParentChildReviewDatesSubform.SetFocus
        'Me.frmParentChildReviewDatesSubform.SetFocus
        'Forms!frmParentChildReviewDates![frmParentChildReviewDatesSubform].SetFocus
        'frmParentChildReviewDatesSubform.Form.dteReviewDate.SetFocus
        Me!frmParentChildReviewDates!frmParentChildReviewDatesSubform.SetFocus       
        Me!dteReview.SetFocus
    End If
End Sub

You can see how many different variations i've tried. It gets so far, the Msgbox message does appear so the IfNull statement is working, but then why i try to set focus back to the first subform, it just won't do it.

Someone put me out of my misery

Mikie

 
Those names are making my head spin
assume
frmMain
subFrmControlOne
with subFrmOne
with txtBoxOne
subFrmControlTwo
with subFrmTwo

from subFrmTwo to set focus on txtBoxOne of subFrmOne within subFrmControlOne:

'set focus on subFrmControlOne
me.Parent.subFrmControlOne.setFocus
'Then set it on the control in the subform
me.Parent.subFrmControlOne.form.txtBoxOne.setFocus
 

Hey MajP

Thanks for the reply, my names do need working on a bit don't they, naming conventions have never been my strongest, i think i make them too big.

Anyways, your suggestion didn't work, i get an error:

Run-time-error '2110':

Microsoft access can't move the focus to the control frmReviewDatesSubform.

I'm not sure why as that's what the subform is called:

Name: frmReviewDatesSubform
Sourceobject: frmParenChildReviewDatesSubform

plus i didn't know what you meant by

frmMain
subFrmControlOne
with subFrmOne
with txtBoxOne
subFrmControlTwo
with subFrmTwo

frm Main is linked to subform1
then subform1 is linked to subform2

not sure if that would make any difference, i'll keep changing your code a bit as i'm sure its just the subform names that are wrong somehow.

Mikie



 
To avoid confusion I use the terms "subform control" and "subform". The thing that you are calling a subform is the subform control. To me the subform is the source object. Many people do not understand this concept and often are referring to the source object when they are talking about the sub form control or vice versa.

So in my naming convention I was just saying you have a main form, with two subform controls, and each subform control has a form within it.

To set focus within a subform from another subform you usually first have to set the focus on the other subform control. Then you can set focus on a control, on the source object, of the subform control. I do not know why you have to do this, but that is the usual trick.

Post your code and the event where you are doing this. My guess you have forget to include the parent property in your reference.
 
Right, i started from scratch again and called my forms something a bit more easier to understand for me.

so here's the code
Code:
Private Sub lngRevuewDateInformation_BeforeUpdate(Cancel As Integer)
If IsNull(Forms!frmReviewDates![frmReviewDatesSub1].Form![dteReviewDate]) Then
        MsgBox "You must enter a Review Date, please go back and enter date to continue"

        'frmParentChildReviewDatesSubform.SetFocus
        Me.Parent.frmReviewDatesSub1.SetFocus
        'Forms!frmParentChildReviewDates![frmParentChildReviewDatesSubform].SetFocus
        Me.Parent.frmReviewDatesSub1.Form.dteReviewDate.SetFocus

    End If
End Sub
So i'm still not sure why it doesn't work

Mikie


 
I would tend to have the form show and enforce the rule you are describing by keeping the frmParentChildReviewDatesSubformInformation disabled until you are ready for them to enter information.

(RG for short) aka Allan Bunch MS Access MVP acXP, ac07 - winXP Pro, Win7 Pro
Please respond to this forum so all may benefit
 
Sorry,
I misread the first post. Although your naming conventions were wrong, the other problem deals with changing focus from the before update event. You can not do that from the BU event. You may want to do the from the enter or got focus event. Or you can set the subform keypreview to true and trap the key press event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top