Results 1 to 12 of 12
  1. #1
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31

    Set focus to a field on a subform

    The Control Source is JobID, the name is txtJobID, it is a combobox on a continuous form on a subform and the user skips over the job number selection and continues. Before the record is saved the before update event kicks in correctly and requests that a job number is selected. That part works, but I would like the focus to go back to the combobox.

    No matter what I try the setfocus comes back with an error message. http://www.mvps.org/access/forms/frm0031.htm
    The accessweb shows that if you are on sub1 refering to sub1 one should be able to use Me!ControlName.Enabled
    My first try in the code below was Me![txtJobID].setfocus

    Here is rest of my code, I am on the subform:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    ''the main form is [FrmHoursInput]


    ''this is on subform [FrmHoursInputSub]
    If IsNull(txtJobID) Then
    Me![FrmHoursInputSub].Form![txtJobID].SetFocus
    Cancel = True
    MsgBox "Go back to JobNo Field and enter a Job Number"
    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    It sounds like this is the subform's before update event? If so, from a "Me" perspective, that control is on that object, so try simply:

    Me.txtJobID.SetFocus
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31

    Thumbs up

    This was too simple, we all the variations I tried, I can't believe I never tried to replace the explamation mark with a period. That was too simple.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Glad it worked for you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31
    Unfortunately, I spoke too soon.
    It worked, now it does not.
    The before update event does not fire all the time, it seems just if there are changes made.
    Back to the drawing board.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    As its name implies, it fires before an update. An update would only happen if something changes. Generally that's what you want. Under what circumstances does that not work for you?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31
    If I tab throught the continuous subform it just keeps going from field to field, but if I change any one number, it recognized that there is a job number missing.

    If, without making changes, the user clicks to a new employee from the combobox on the main form, it leaves the subform record without the error message that one jobID is missing.

    I am trying to catch that if there is a jobID missing, the program will not let the user leave the form before completing the missing field. It now catched the missing field on my original form and does not let me change employees before completing the job number. This is how I want it to work.
    I find it somewhat disturbing, that it works sometimes and sometimes it does not. Right now the event works on my original form, when it did not an hour ago. I have a second form which has the same criteria. I copied the code for the beforeupdate event to this form and it does not work there, it totally ignores that the event exists.

    What am I looking for?

    me.txtjobID.setfocus does not work anywhere.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Is jobID a required field at the table level?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31
    No, its the primary key, no duplicate in the tbljobs.

  10. #10
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31
    I got it. If there is no change made, the event does not fire. I am working with after the fact data, and the missing job entry was already there before my code. On new data, it is working.

    I would still like to like to be able to send the focus back to the jobID. That part is not working

  11. #11
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31
    I got the answer from another Forum
    cancel = true must be before
    Me.txtJobID.SetFocus

  12. #12
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Some things I try when having troubles setting the focus on a subform....

    1. Use the syntax: Forms!MyMainFormName!MySubFormName!MyFieldName.set focus versus the .Form! syntax.
    2. Set the focus to the subform itself or to another field first.
    ie.
    Forms!MyMainFormName!MySubFormName.setfocus
    Forms!MyMainFormName!MySubFormName!SomeOtherField. setfocus
    Forms!MyMainFormName!MySubFormName!MyFieldName.set focus
    3. Make sure the field I'm setting the focus to is enabled.
    4. Manipulate the tab order itself of the subform.
    5. Try issuing a me.repaint (or Refresh) command before the .setfocus command.

    Sometimes when having problems with setting the focus to a field on a subform, I'll notice if there is a message box within the code, if that message box appears, it will then set the focus correctly (otherwise it doesn't). This can usually be resolved by using the me.repaint or refresh command.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing focus to subform.....
    By smorelandii in forum Forms
    Replies: 3
    Last Post: 02-04-2011, 10:51 AM
  2. Replies: 9
    Last Post: 12-15-2010, 01:44 PM
  3. Replies: 15
    Last Post: 11-09-2010, 04:27 PM
  4. Replies: 3
    Last Post: 11-05-2010, 03:10 PM
  5. Replies: 1
    Last Post: 05-29-2010, 02:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums