If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > User Forms & Setting Focus

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-08, 06:08
JezLisle JezLisle is offline
Registered User
 
Join Date: Apr 2007
Location: Stalybridge, Manchester
Posts: 273
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
Reply With Quote
  #2 (permalink)  
Old 11-05-08, 08:32
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On