Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Working with dates and text boses..........


Ok I have one more question on my little project I'm working on. For
those that have helped in guiding me, THANK YOU! This forum is
actually really really great, I'm glad I found it! I've already told
like 10 people about it.

I simply have a text box field with a label name of, "Date." When a
form loads in VBS the user is to enter a specific date. This date then
stores in a cell on a particular worksheet.

I currently have the text box set up so that no matter what you type
in, it will store the value in the cell. However, I know there is a
way to have the text box set up so that when the user types into it,
the, "/"'s are already loaded and all they have to type is the
numerical date. For example, the user would only have to type in,
"932007" and the text box will show, "9/3/2007". Can someone help me
in coding this text box so it's set up in this manner??

Also, how would I code a text box to automatically show a dollar sign
("$") in which it is to hold a dollar amount?

Thanks!!




--
chadtastic
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Working with dates and text boses..........

You might try something like the following. The code accepts 4, 6, or 8
character date strings (mdyy, mmddyy, mmddyyyy). Anything else is an error.


Private Sub CommandButton1_Click()
Dim S As String
Dim D As Date
S = Me.TextBox1.Text
On Error GoTo ErrHandler:
Select Case Len(S)
Case 4
' assumed to be mdyy, in 2000 century
D = DateSerial(Year:=CInt(Mid(S, 3, 2)) + 2000, _
Month:=CInt(Mid(S, 1, 1)), Day:=CInt(Mid(S, 2, 1)))
Case 6
' assumed to be mmddyy
D = DateSerial(Year:=CInt(Mid(S, 5, 2)), _
Month:=CInt(Mid(S, 1, 2)), Day:=CInt(Mid(S, 3, 2)))
Case 8
' assumed to be mmddyyyy
D = DateSerial(Year:=CInt(Mid(S, 5, 4)), _
Month:=CInt(Mid(S, 1, 2)), Day:=CInt(Mid(S, 3, 2)))
Case Else
MsgBox "Invalid date"
Exit Sub
End Select

Worksheets("Sheet1").Range("A1").Value = D
Exit Sub
ErrHandler:
MsgBox "Invalid Date"
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"chadtastic" wrote in message
...

Ok I have one more question on my little project I'm working on. For
those that have helped in guiding me, THANK YOU! This forum is
actually really really great, I'm glad I found it! I've already told
like 10 people about it.

I simply have a text box field with a label name of, "Date." When a
form loads in VBS the user is to enter a specific date. This date then
stores in a cell on a particular worksheet.

I currently have the text box set up so that no matter what you type
in, it will store the value in the cell. However, I know there is a
way to have the text box set up so that when the user types into it,
the, "/"'s are already loaded and all they have to type is the
numerical date. For example, the user would only have to type in,
"932007" and the text box will show, "9/3/2007". Can someone help me
in coding this text box so it's set up in this manner??

Also, how would I code a text box to automatically show a dollar sign
("$") in which it is to hold a dollar amount?

Thanks!!




--
chadtastic


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Working with dates and text boses..........

Typo alert:

Case 6
' assumed to be mmddyy
D = DateSerial(Year:=CInt(Mid(S, 5, 2)), _
Month:=CInt(Mid(S, 1, 2)), Day:=CInt(Mid(S, 3, 2)))


should be

Case 6
' assumed to be mmddyy
D = DateSerial(Year:=CInt(Mid(S, 5, 2)) + 2000, _
Month:=CInt(Mid(S, 1, 2)), Day:=CInt(Mid(S, 3, 2)))


Sorry for any confusion.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Chip Pearson" wrote in message
...
You might try something like the following. The code accepts 4, 6, or 8
character date strings (mdyy, mmddyy, mmddyyyy). Anything else is an
error.


Private Sub CommandButton1_Click()
Dim S As String
Dim D As Date
S = Me.TextBox1.Text
On Error GoTo ErrHandler:
Select Case Len(S)
Case 4
' assumed to be mdyy, in 2000 century
D = DateSerial(Year:=CInt(Mid(S, 3, 2)) + 2000, _
Month:=CInt(Mid(S, 1, 1)), Day:=CInt(Mid(S, 2, 1)))
Case 6
' assumed to be mmddyy
D = DateSerial(Year:=CInt(Mid(S, 5, 2)), _
Month:=CInt(Mid(S, 1, 2)), Day:=CInt(Mid(S, 3, 2)))
Case 8
' assumed to be mmddyyyy
D = DateSerial(Year:=CInt(Mid(S, 5, 4)), _
Month:=CInt(Mid(S, 1, 2)), Day:=CInt(Mid(S, 3, 2)))
Case Else
MsgBox "Invalid date"
Exit Sub
End Select

Worksheets("Sheet1").Range("A1").Value = D
Exit Sub
ErrHandler:
MsgBox "Invalid Date"
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"chadtastic" wrote in message
...

Ok I have one more question on my little project I'm working on. For
those that have helped in guiding me, THANK YOU! This forum is
actually really really great, I'm glad I found it! I've already told
like 10 people about it.

I simply have a text box field with a label name of, "Date." When a
form loads in VBS the user is to enter a specific date. This date then
stores in a cell on a particular worksheet.

I currently have the text box set up so that no matter what you type
in, it will store the value in the cell. However, I know there is a
way to have the text box set up so that when the user types into it,
the, "/"'s are already loaded and all they have to type is the
numerical date. For example, the user would only have to type in,
"932007" and the text box will show, "9/3/2007". Can someone help me
in coding this text box so it's set up in this manner??

Also, how would I code a text box to automatically show a dollar sign
("$") in which it is to hold a dollar amount?

Thanks!!




--
chadtastic



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text to Columns not working correctly with dates in Excel 2007 AL123 Excel Discussion (Misc queries) 5 February 26th 07 11:44 PM
Working with Dates Byron720 Excel Worksheet Functions 3 December 28th 06 12:02 AM
working with dates Hru48 Excel Discussion (Misc queries) 2 January 31st 06 12:34 PM
Working with dates Sandy Excel Worksheet Functions 3 November 21st 05 07:23 PM
working with dates Phil kelly Excel Discussion (Misc queries) 2 June 21st 05 12:05 PM


All times are GMT +1. The time now is 08:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"