Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using variables for field names ((2000 (9.0.4402 SR-1)) )

    I have a data input form where if the user clicks on the close button a message box asks the user to confirm Yes or No to whether they really want to quit. If Yes then the form closes without saving any changes, if No the user is returned to the form, where any data entered is still present in its respective field and the user can carry on.

    The problem I have is when the user is returned to the form the cursor is not present in any of the fields where data entry can occur. The user has to re-select a field to continue the data entry. For User friendly sake, I have come up with a way of returning the user to the last field selected by using the following example:-

    private currentfield as string

    currentfield = Me.ActiveControl.Name

    If currentfield = "INVOICE_NO" Then
    Me.INVOICE_NO.SetFocus

    Else

    If currentfield = "TOTAL_DUE" Then
    Me.TOTAL_DUE.SetFocus

    end if
    end if

    The currentfield variable is set in the On Got Focus area of the selected field.

    This works ok, but I wondering if there is a more compact method such as

    Me.currentfield.SetFocus?

    I have tried that, but I get "Compile Error: Method or Data Member not found" and am stumped as to turning up any other methods.

    Would be most grateful for some guidance here.

    Cheers,

    Niven

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using variables for field names ((2000 (9.0.4402 SR-1)) )

    You could use :
    Screen.PreviousControl.SetFocus
    Francois

  3. #3
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using variables for field names ((2000 (9.0.4402 SR-1)) )

    Good Man!

    That was the piece of simplicity I was looking for.

    Cheers,

    Niven <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

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

    Re: Using variables for field names ((2000 (9.0.4402 SR-1)) )

    You can use the Screen.PreviousControl property:

    Screen.PreviousControl.SetFocus

    Alternatively, you could use your code, with

    Me.Controls(currentfield).SetFocus

    instead of

    Me.currentfield.SetFocus

  5. #5
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using variables for field names ((2000 (9.0.4402 SR-1)) )

    This is excellent too!

    I thought I could use the Me.Controls function but kept messing it up.

    Cheers again,

    Niven <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Using variables for field names ((2000 (9.0.4402 SR-1)) )

    Couldn't you also use

    Me(currentfield).SetFocus

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

    Re: Using variables for field names ((2000 (9.0.4402 SR-1)) )

    Yes, Me(...) is equivalent to Me.Controls(...), since Controls is the default property of a form.

Posting Permissions

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