+ Reply to Thread
Results 1 to 3 of 3

BeforeUpdate event to Force TextBox Value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    BeforeUpdate event to Force TextBox Value

    Hello everyone. How can I use the BeforeUpdate of a textbox to force the textbox to only accept certain values in this case short hand dates: mm/dd/yyyy?

  2. #2
    Registered User
    Join Date
    03-24-2014
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: BeforeUpdate event to Force TextBox Value

    You can try this:

    Private Sub Textbox_BeforeUpdate()
    If Textbox.Value = "" Or Textbox.Text <> Format(Textbox.Text, "mm-dd-yyyy") Then
        MsgBox ("Enter a Valid Expiration Date (mm-dd-yyyy)")
        Textbox.Value = ""
        Cancel = True
        Textbox.SetFocus
        Exit Sub
    Else
        'What to do (if anything) if valid.
    End if
    End Sub
    Last edited by jeffreybrown; 02-05-2019 at 06:56 PM. Reason: Please use code tags!

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: BeforeUpdate event to Force TextBox Value

    Hi srpinaz,

    Not sure Anthony is still waiting for an answer to this thread! However, if he is, his project is awfully delayed after 9 years. Anyway, please use code tags when posting code.
    HTH
    Regards, Jeff

+ 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