Consulting

Results 1 to 8 of 8

Thread: Solved: Input Box

  1. #1
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location

    Solved: Input Box

    Hi Hello All,

    I have an inputbox to allow user to input the date, then it will go into a excel for some calucation.

    I set it up like this

    UserForm1.datestart.Text = Format(Date, "dd-mm-yyyy")
    UserForm1.dateend.Text = Format(Date, "dd-mm-yyyy")

    But when the user input for example, 11/1/08

    it will come into excel as an error, excel gets confuse with the year, 1908 and 2008.

    Is there a way that I can force the user to input a 4-digit year instead?

    Also, The User have to input a start and end date, when I set it up in this format, there is a default date on there and it changes everyday. For example right now, on both boxes, the date is 7/12/2008, but yesterday, they said 6/12/2008.

    I want to make sure that the user inputs the date range before the run the command button for the calucation. Is there a way to generation a message box if they dont' enter in a new date?

    thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    On the first part, are you saying you want 11/1/08 to be 1908, as it returns 2008 for me.

    On the second, remove the default.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location
    oh no, i want it to be 2008, but if the user input 1/8/08, excel will not accept it as a date because it doesn't know what the year is (look at image).

    I want to force the user to input the year in 4 - digit format.

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,194
    Location
    Rather than setting the inputbox to a format you need to set the output format like this...

    MsgBox Format(TextBox1.Value, "dd/mm/yyyy")

    then you can input it like 1/1/8 and it will come out in date format.

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  5. #5
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location
    I did that but still get the same result, the problem is not that it did not put it in date format. it is in a date format but then excel doens't know if it's 1908 or 2008.

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,194
    Location
    I edited with an attatchment have a look.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Cast it

    [vba]

    Range("C1").Value = CDate(datestart.Text)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location

    Solved: Input Box

    it worked. thanks xld

Posting Permissions

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