• Userforms (VBA Excel ’97)

    Author
    Topic
    #365474

    1) I have created a userform to input data, but i wish to stop people useing a full stop for dates. I.e 16.01.02 instead of 16/01/02 for 16th January 2002, is there anyway i can either use VBA so that as soon as they exit the textbox it changes the . to / or to use VBA to see if the textbox contains . and throw up an error message of my design????

    2) I wish to automatically have the 1st of the current month input into a textbox when the userform in initialised, does anyone know how to do this???

    Please help!

    Viewing 0 reply threads
    Author
    Replies
    • #564234

      Come on guys, it seems to be a rather simple problem??? PLEASE Help

      • #564237

        2 hours isn’t long to wait…

        For your first question, you might like to use something like

        Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
            If KeyAscii = Asc(".") Then KeyAscii = Asc("/")
        End Sub
        

        You may also want to put in checks for Alphabetic characters or other things that aren’t date-like.

        For your second question, a quick search of this forum (for the string “Month”) would have led you to this thread, which gives the elegant…

        Private Sub UserForm_Activate()
            TextBox1.Text = Date - Day(Date) + 1
        End Sub
        

        StuartR

    Viewing 0 reply threads
    Reply To: Userforms (VBA Excel ’97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: