|
-
Jan 12th, 2006, 02:27 PM
#1
Thread Starter
Member
VB Excel User forms
VB Code:
Private Sub txtIssuedDate_AfterUpdate()
txtIssuedDate = Format(txtIssuedDate, "MMM/DD/YYYY")
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
-
Jan 12th, 2006, 02:31 PM
#2
Re: VB Excel User forms
Excel VBA question moved to Office Development
-
Jan 12th, 2006, 02:56 PM
#3
Re: VB Excel User forms
VB Code:
Private Sub txtIssuedDate_AfterUpdate()
txtIssuedDate = Format(txtIssuedDate, "MM/DD/YYYY")
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 12th, 2006, 03:13 PM
#4
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
-
Jan 12th, 2006, 03:18 PM
#5
Lively Member
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:
Private Sub txtDate_AfterUpdate()
'DATE ENTRY FORMAT VALIDATION
If IsDate(txtDate.Value) Then
txtDate.Value = Format(CDate(txtDate.Text), "mmm/dd/yy")
Else
MsgBox "Entry must be in date format, MM-DD-YY" & vbCr & _
"Entry will revert to current date.", vbExclamation + vbOKOnly, "Incorrect Date Format!"
txtDate.Value = Format(CDate(Date), "mmm/dd/yy")
End If
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 )
-
Jan 12th, 2006, 03:24 PM
#6
Thread Starter
Member
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
-
Jan 12th, 2006, 03:25 PM
#7
Thread Starter
Member
Re: VB Excel User forms
New2vba
I am going to try your coding thanks
-
Jan 12th, 2006, 03:30 PM
#8
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|