View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
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