Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SetFocus command (2000)

    I would like to use the SetFocus so that it automatically goes to this field first when adding new records.
    But l have a problem in that the field l have used consists of two words and l know that Access has problems in reading fields of this format.
    Is there a solution round this problem?
    see attachment.

    Justin.

  2. #2
    New Lounger
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    Try setting the Tab Index to Zero.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    l am not to sure how to do this.
    Please can you explain.
    If possible could you include a screenshot.

    Regards
    Justin.

  4. #4
    New Lounger
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    Click the control you want to have the focus.
    In the Properties dialog, Click Other and change the Tab Index setting to 0

  5. #5
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    It appears to already to be set to 0.
    Any other ideas?

  6. #6
    New Lounger
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    How are you adding new records?

  7. #7
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    I click on an add record button.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: SetFocus command (2000)

    You could use the On Current event of the form:
    - Open the form in design view.
    - Activate the Event tab of the database window.
    - Click in the On Current event.
    - Select [Event Procedure] from the dropdown list.
    - Click the ... button to the right of the dropdown arrow.
    - Complete the code to look like this:

    Private Sub Form_Current()
    ' Are we on a new record?
    If Me.NewRecord Then
    ' Set focus to CDRL Ref
    Me.[CDRL Ref].SetFocus
    End If
    End Sub

    The square brackets around the control name are required if it contains spaces and/or punctuation.

  9. #9
    New Lounger
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    Use the Control wizard
    Add a Button control
    Select Record Operations and add new Record
    click Next, Next, and Finish

    Select from, the Properties dialog, Event and On Click, click the elipisis. Your code shouls look like:


    Private Sub Command5_Click()
    On Error GoTo Err_Command5_Click

    DoCmd.GoToRecord , , acNewRec

    Exit_Command5_Click:
    Exit Sub

    Err_Command5_Click:
    MsgBox Err.Description
    Resume Exit_Command5_Click

    End Sub

    Modify it look like: (Assume your Text Box is frmSomeText)

    Private Sub Command5_Click()
    On Error GoTo Err_Command5_Click

    DoCmd.GoToRecord , , acNewRec
    Me.frmSomeText.SetFocus

    Exit_Command5_Click:
    Exit Sub

    Err_Command5_Click:
    MsgBox Err.Description
    Resume Exit_Command5_Click

    End Sub

    Hope this does it for you.

  10. #10
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    Is the control in the Detail section?
    Are its properties set as follows:
    Enabled = Yes
    Locked = No
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  11. #11
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    yes, the control is in the detail section.

    Justin.

  12. #12
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    I have tried this but appear to get an error when l click on the "Add record" button.
    see attachment.

    Justin.

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: SetFocus command (2000)

    Make sure that you use the exact name of the control; it might be different from what was shown in your screenshot.

  14. #14
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    Can you tell me where l can find the exact name of the control?

    Thanks
    Justin

  15. #15
    5 Star Lounger
    Join Date
    Mar 2004
    Posts
    924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus command (2000)

    I have changed the coding so that the control name is correct.
    But appear to be getting yet another error, see attachment.

    Justin

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •