+ Reply to Thread
Results 1 to 8 of 8

Setting initial value in userform field with current data

  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Mooresville NC
    MS-Off Ver
    Excel 2010
    Posts
    20

    Setting initial value in userform field with current data

    I have a custom userform (dialog box) that prompts the operator(s) for some info. one of these being the date. 98% of the time it will be the current day's date. I really coould not find an example that gave me what I need for this. I seem to be having the issue with format as the Date method or Now method returns the date in a date format but I need the entry to end up as a text format (Or if I can configure the field as a date field and the corresponding Public variable in the top level macro as a date format)

    This is what I have at this point

    Please Login or Register  to view this content.

    If anyone knows how I can achieve this, it would be much appreciated.

    Doug

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Doug

    Where's the code to put the date in a control on the userform?
    If posting code please use code tags, see here.

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Setting initial value in userform field with current data

    Doug,

    On a UserForm there are no field types that you can define as date.

    You can initialise the date field upon form opening using the below code

    Please Login or Register  to view this content.
    The code in the xDate_Change routine could be changed to the below code to make it slightly more robust.

    Please Login or Register  to view this content.
    The public variable vDate should be declared as Date and the assignment code should be

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  4. #4
    Registered User
    Join Date
    01-28-2013
    Location
    Mooresville NC
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Setting initial value in userform field with current data

    I guess that is what I am missing.

    I did try UserForm.xDate.Value = Now() and also tried this with Date but to no avail. That's why I figured I am not even in the ballpark.

  5. #5
    Registered User
    Join Date
    01-28-2013
    Location
    Mooresville NC
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Setting initial value in userform field with current data

    Ollie,

    That works, Thanks. Only problem is that the Month and Day are correct but the year comes up to 1356. Not even sure where that year comes from.

    Any thoughts on that?

    Did not realize that the term Me was available for use in ref to a userform. Is that true for all private subs or just userforms ?

    Thanks

    Doug

  6. #6
    Registered User
    Join Date
    01-28-2013
    Location
    Mooresville NC
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Setting initial value in userform field with current data

    Oops. Had left a 'y' out in one of the year formats. That fixed the year. Now just curious about the Me method.

    Thanks again

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Setting initial value in userform field with current data

    - Me is available in Forms and Classes, and I think also for private routines linked to worksheets but I am not sure about that last one - never used it myself
    - Where exactly are you getting/seeing year 1356?

  8. #8
    Registered User
    Join Date
    01-28-2013
    Location
    Mooresville NC
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Setting initial value in userform field with current data

    Acknowledged on Me.

    Got the funky date becasue I had yyy instead of yyyy in the first private sub. Added the fourth y and all was good.

    Thanks for the info. Been on a steep learning curve as I only started with the VB less than 4 weeks ago. But with the help of this forum and lots of experimentation, I'm making progress.

    Doug

+ 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