Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    May 2001
    Location
    Engerland
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel 97 SetFocus

    Hi,

    I'm trying to validate textboxes on a userform to ensure that the entries are numeric - if not to delete the entry and place the cursor in the original textbox. I've tried to to use the following:

    txtAmount.setfocus

    but I get run time error `2110` - that the control is invisible, not enabled or of a type that does not accept the focus. What am I doing wrong!!

    TIA

    Ade

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Excel 97 SetFocus

    What procedure are you using to validate the contents, and where is it placed ?.

    If possible could you post a copy of the file containing just the userform and the procedures used by it (no data necessary).

    Andrew C

  3. #3
    Lounger
    Join Date
    May 2001
    Location
    Engerland
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel 97 SetFocus

    Code is as follows:

    Select Case txtAmt_Paid

    Case IsNumeric(txtAmt_Paid.Value)
    Exit Sub
    Case Else
    MsgBox "Enter an Amount!", vbExclamation
    txtAmt_Paid.Value = ""
    txtAmt_Paid.SetFocus
    End Select

    Thanks...Ade

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Excel 97 SetFocus

    Ade,

    Sorry to be asking questions (you want answers), but where is that code placed, and is the Userform still loaded whilst it is being executed ?

    At the very least I suspect you should include the Userform name when referring to the textbox, e.g. UserForm.txtAmt_Paid, where UserForm is the name of the form in use. Try it and see if it helps.

    Andrew C

  5. #5
    Lounger
    Join Date
    May 2001
    Location
    Engerland
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel 97 SetFocus

    S'ok, am grateful for the help.

    The code is placed on the exit event of the txtAmt_Paid textbox, the userform is loaded when executing. I tried prefacing with the name of the userform and with 'me' but this doesn't appear to make any difference.

    The bit that replaces the non-numeric entry with "" works fine though, even without any reference to the name of the form.

    Ade

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Excel 97 SetFocus

    If you do not mind using a different approach, have a look at <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Cat=&Board=vb&Number=37861&page=&v iew=&sb=&vc=1#Post37861>This Post</A> in the VB VBA forum, which achieves the same result using the KeyPress event.

    Andrew C

Posting Permissions

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