Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273

    Unanswered: User Forms & Setting Focus

    I have a User form that has a TextBox on, within that the user will input a date. I have an AfterUpdate routine on the TextBox to check the format of how the date has been input.

    My problem is that if the date isnt in the correct format I want after the MsgBox to set focus on the the TextBox again but it doesnt like to do that and always goes onto the next TextBox.

    How can I get around this?

    Code:
    Private Sub txtDateSource1_AfterUpdate()
        If Me.txtDateSource1 <> Format(Me.txtDateSource1, "dd/mm/yy") Then
            MsgBox "You must input the Order Date as dd/mm/yy before continuing.", vbExclamation, "Wrong Date"
            txtDateSource1.SetFocus
            Exit Sub
        End If
    End Sub

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Quote Originally Posted by JezLisle
    I have a User form that has a TextBox on, within that the user will input a date. I have an AfterUpdate routine on the TextBox to check the format of how the date has been input.

    My problem is that if the date isnt in the correct format I want after the MsgBox to set focus on the the TextBox again but it doesnt like to do that and always goes onto the next TextBox.

    How can I get around this?

    Code:
    Private Sub txtDateSource1_AfterUpdate()
        If Me.txtDateSource1 <> Format(Me.txtDateSource1, "dd/mm/yy") Then
            MsgBox "You must input the Order Date as dd/mm/yy before continuing.", vbExclamation, "Wrong Date"
            txtDateSource1.SetFocus
            Exit Sub
        End If
    End Sub
    Hi

    You could use the textBox BeforeUpdate event and set the Cancel property to True if validation fails.

    Focus will then remain in the TextBox

    ??

    MTB

Posting Permissions

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