+ Reply to Thread
Results 1 to 6 of 6

UserForm label to show current date

  1. #1
    Registered User
    Join Date
    11-09-2013
    Location
    Tel Aviv
    MS-Off Ver
    Excel 2007
    Posts
    6

    UserForm label to show current date

    Hi everyone,

    Im a new user in here and im trying to learn vba.

    I have a form which i created throught vba, now im trying to add the code to it.

    This form is opened by the user when he wants to add current data to the database.

    I want to have a label with the current date on it, when the form is opened.

    This is the code i tryied to modify:

    Private Sub SellForm_Initialize()
    ' Dlbl is the date function
    Dim Dlbl As Date
    Dlbl = DateValue(Now)

    Datelbl.Caption = Dlbl

    End Sub

    Well, As you can guess, it not working and the label's caption is empty....

    What is wrong? Is this the right way to do it?

    Thank you very much!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: UserForm label to show current date

    Try just:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: UserForm label to show current date

    How do you call the routine SellForm_Initialize, as that is not the default Initialize event for a userform

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    11-09-2013
    Location
    Tel Aviv
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: UserForm label to show current date

    Doesn't work... The form just open and nothing is written in the current label for some reason...

    I Also tried Saving and the running the macro but still doesn't work.. BTW im using excel 2007 if it matters

  5. #5
    Registered User
    Join Date
    11-09-2013
    Location
    Tel Aviv
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: UserForm label to show current date

    Hey Andy, What do you mean? I've changed the form's name to SellForm

    Andy, It worked! Thanks!

    Can you explain to me why?

    I though that if I change the form's name so the in the code I need to reffer to the userform new name

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: UserForm label to show current date

    The userforms initialize event does not change to include the userforms name.

    What you created was simple a subroutine within the userform.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. userform combobox to show current month
    By losmi8 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2014, 04:45 AM
  2. [SOLVED] Userform to show date format in textbox or label
    By coach.32 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-17-2013, 08:55 PM
  3. [SOLVED] Show label in UserForm
    By jdasp49 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-16-2013, 09:30 AM
  4. UserForm show cell value with the current Date and Tme
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-12-2011, 09:17 AM
  5. Label to display current Date, Time
    By robbert in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2008, 04:18 PM

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