Results 1 to 8 of 8

Thread: VB Excel User forms

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Toronto, Canada
    Posts
    41

    VB Excel User forms

    VB Code:
    1. Private Sub txtIssuedDate_AfterUpdate()
    2.     txtIssuedDate = Format(txtIssuedDate, "MMM/DD/YYYY")
    3. End Sub

    How can i format date ?
    When i type 01/01/2005, txtIssuedDate changed to Oct/09/4670

    How come i am not getting Jan/01/2005?

    Thank you in advance

    Pretty
    Last edited by RobDog888; Jan 12th, 2006 at 02:55 PM. Reason: Added [vbcode] tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB Excel User forms

    Excel VBA question moved to Office Development

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB Excel User forms

    VB Code:
    1. Private Sub txtIssuedDate_AfterUpdate()
    2.     txtIssuedDate = Format(txtIssuedDate, "MM/DD/YYYY")
    3. End Sub
    The "MMM" specifies the short version of the month name. Use just "MM" to get the 2 digit month index number.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: VB Excel User forms

    Assuming you did want the short month name, I don't know. I've tried it in Excel and it works in both cells and in a textbox on a Userform.
    Can you be more specific?

    zaza

  5. #5
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: VB Excel User forms

    I had similar problem and this fixed it - entries into this text box (which are on a userform) act just like cells in excel with date format applied, i.e. entering 01-01 should give you Jan/01/06.

    VB Code:
    1. Private Sub txtDate_AfterUpdate()
    2.      
    3. 'DATE ENTRY FORMAT VALIDATION
    4.      
    5.     If IsDate(txtDate.Value) Then
    6.     txtDate.Value = Format(CDate(txtDate.Text), "mmm/dd/yy")
    7.     Else
    8.     MsgBox "Entry must be in date format, MM-DD-YY" & vbCr & _
    9.     "Entry will revert to current date.", vbExclamation + vbOKOnly, "Incorrect Date Format!"
    10.     txtDate.Value = Format(CDate(Date), "mmm/dd/yy")
    11.     End If
    12.    
    13. End Sub

    This may be slightly different in that I load the text box with the current date when my userform is initialised. This code also reverts the value to the current date if the user does not enter a valid format.

    It may not be the best way to do it (I am a novice at best), but it works for me. Hope it helps.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Toronto, Canada
    Posts
    41

    Re: VB Excel User forms

    Private Sub txtIssuedDate_AfterUpdate()
    txtIssuedDate = Format(txtIssuedDate, "MMM/DD/YYYY")
    End Sub

    MM or MMM both do samething..

    Excel worksheet - i have no problem formatting the field..
    Only with userform, textbox "txtIssuedDate" does not working the way i wanted with after_update method.
    when users type 01/01/2005........i want the txtbox to change either jan/01/2005 or 01/01/2005 but its not working that way.

    i am getting wrong dates in both format.
    hmmm
    thank you in advance
    any help will be appreciated......

    pretty
    recent grad

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Toronto, Canada
    Posts
    41

    Re: VB Excel User forms

    New2vba
    I am going to try your coding thanks

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Toronto, Canada
    Posts
    41

    Re: VB Excel User forms

    it worked perfectly.........

    thank you so muchhhhhhhhhhhhhhhhhh

Posting Permissions

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



Click Here to Expand Forum to Full Width