+ Reply to Thread
Results 1 to 3 of 3

Textbox highlighting issue

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Textbox highlighting issue

    I have a number of textboxes on a userform. When the user enters data beyond accepted paramaters,

    1. an error message is generated
    2. the form 'close' button is locked (& changes color)
    3. the offending input textbox changes color.

    I also would like the cursor to return to the offending textbox after step 3 - how do I do this ? (apologies for what must be a basic problem).

    Here is a sample of the code I am using:

    Private Sub EnterInfo_Click()

    If txtStaff.Text = "" Then
    MsgBox "Please enter number of staff", 64, "Error Message"
    CloseButton.Locked = True
    CloseButton.BackColor = &H80000013
    txtStaff.BackColor = &H80000013

    Else
    If txtStaff >= 0 Then
    CloseButton.Locked = False
    CloseButton.BackColor = &H80000010
    txtStaff.BackColor = &H80000005


    Any help much appreciated

    Cheers

    Peter (new to VBA)

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Peter,

    You just set the focus back on the TextBox. See your code below. The method is in bold type.

    Private Sub EnterInfo_Click()

    If txtStaff.Text = "" Then
    MsgBox "Please enter number of staff", 64, "Error Message"
    CloseButton.Locked = True
    CloseButton.BackColor = &H80000013
    txtStaff.BackColor = &H80000013
    txtStaff.SetFocus

    Else
    If txtStaff >= 0 Then
    CloseButton.Locked = False
    CloseButton.BackColor = &H80000010
    txtStaff.BackColor = &H80000005

    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161
    Thanks Leith - steep learning curve this VBA!

    Cheers

    Peter

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1