Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jul 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Move data to new text box using Before Update (2003)

    I need to stop data from being written to a textbox under certain conditions (in my case, if the entry exceeds 8 characters). If wrong (ie. too long) data is entered, I want to move to a different textbox & paste the data (I need this 'wrong' data). Using the below code, I trigger the before update event when I input a value of 9 or more characters, however, it errors out when I try to change the location to a different textbox. I played around with 'cancel=true' and 'Text1.undo' but neither worked. I haven't used this event much, but seems to was designed with data validation in mind.

    Thanks for any help/ suggestions Ralph

    Private Sub txtInput2_BeforeUpdate(Cancel As Integer)
    If Len(Me.txtInput2) > 8 Then
    'Cancel = True
    'Me.txtInput2.Undo
    Me.txtInput14.SetFocus 'errors out

    End If

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

    Re: Move data to new text box using Before Update (2003)

    You could use the On Change event:

    Private Sub txtInput2_Change()
    If Len(Me.txtInput2.Text) > 8 Then
    Me.txtInput2.Text = Left(Me.txtInput2.Text, 8)
    Me.txtInput14.SetFocus
    End If
    End Sub

    or the On KeyPress event:

    Private Sub txtInput2_KeyPress(KeyAscii As Integer)
    If Len(Me.txtInput2.Text) > 7 And Not KeyAscii = vbKeyBack Then
    KeyAscii = 0
    Me.txtInput14.SetFocus
    End If
    End Sub

  3. #3
    New Lounger
    Join Date
    Jul 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Move data to new text box using Before Update (2003)

    Thanks Hans,

    As usual you have solved my problem. Solution1 (which I never thought of using; trimming the input) works perfectly. I am using this db to monitor 35 alarm inputs. When there is a 'real' alarm, my program adds a "=" to the end of the time value (and causes an error in my time/date field). Your 'trimming' code prevents the error & allows me to keep the (important time) value.

    Thanks!!!

    Ralph

Posting Permissions

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