Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tab order/move focus (97)

    The main form of my database includes a few text boxes in the usual way. I've put a button on the form which creates a new record using the following code:

    Private Sub Command40_Click()
    On Error GoTo Err_Command40_Click

    DoCmd.GoToRecord , , acNewRec

    Exit_Command40_Click:
    Exit Sub

    Err_Command40_Click:
    MsgBox Err.Description
    Resume Exit_Command40_Click

    End Sub

    Two questions:

    1) How do I get the focus to be on the first text box on the new blank form instead of the new record form?
    I tried 'DoCmd.GoToControl CompanyName' but it caused an error, syntax maybe?

    2) How do I change the text that appears in an error message box when the text is produced by the 'MsgBox Err.Description' as above?



    All sugestions gratefully received.

    Regards

    Graeme

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

    Re: Tab order/move focus (97)

    1. I don't understand "... on the new blank form instead of the new record form", but you can set focus to a control by using

    Me.CompanyName.SetFocus

    2. You can either put a fixed text in the place of Err.Description:

    MsgBox "Something has gone terribly wrong."

    or you can create your own message texts based on the error number. For this, you have to get an idea of the errors that can occur, by temporarily changing MsgBox Err.Description to

    MsgBox "Error " & Err.Number & "with description: " & Err.Description

    During testing, write down the number and description of each error that occurs. Then, use these as follows in the error handling sector (this example is entirely fictitious)

    Select Case Err.Number
    Case 9876 ' can't go to new record
    MsgBox "Sorry, you can't create a new record now."
    Case 5432 ' can't save current record
    MsgBox "The current record cannot be saved."
    Case Else ' you didn't see this one coming
    MsgBox "Unexpected error: " & Err.Description
    End Select

  3. #3
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tab order/move focus (97)

    Hans

    Thanks for the reply

    I guess you didn't understand 'new blank form instead of the new record form' because it doesn't make sense! It should have read 'new blank form instead of the new record button'.

    I'll put the 'Me.CompanyName.SetFocus' code at the end of the New Customer button click event sub routine. Thanks

    The Err.Description I need to change, for clarity for the user, is;

    Syntax error (missing operator) in query expression '(SiteAddressID)='.

    The main form lists customers and includes a subform displaying address summaries for the displayed customer. A button on the subform opens the address details form. The error is generated when the button is clicked by the user when the address summary sub form is blank since there is no address details record to display.

    So I would like to display an error message to tell the user to enter an address summary before opening the main address form.

    I'll go away and try your suggestion.

    Regards

    Graeme

  4. #4
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tab order/move focus (97)

    The Me.CompanyName.SetFocus code worked a treat thanks

  5. #5
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Tab order/move focus (97)

    Success as always!!!

    The Select Case error handling worked a treat too

    Thanks

Posting Permissions

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