Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default how to generate date error message

I have a user form that works great but I have one last item to fix.
If someone types in a date wrong, it will not update the spreadsheet
with any info and does not give an option to fix the date. What I
would like is an error message and not to update the spreadsheet but
to be able to fix the date. Once that is done, click on OK and then
it can update sheet.
Here is what I have:


Private Sub OK_Click()
Dim RowCount As Long

If Me.txtName.Value = "" Then
MsgBox "Please enter Employee's name", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTPRI.Value = "" Then
MsgBox "Please enter Employee's PRI", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.CBODEPARTMENT.Value = "" Then
MsgBox "Please Choose a Department", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.cboPSHCPLEVEL.Value = "" Then
MsgBox "Please Choose PSHCP Level", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTDEDUCTIONDATE.Value = "" Then
MsgBox "Please Enter a Deducton Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTCOVERAGEDATE.Value = "" Then
MsgBox "Please Enter a Coverage Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
RowCount =
Worksheets("PSHCP").Range("A1").CurrentRegion.Rows .Count
With Worksheets("PSHCP").Range("A1")
.Offset(RowCount, 7).Value = Format(Now, "dd/mmm/yyyy
hh:nn:ss") & Application.UserName
.Offset(RowCount, 0).Value = Me.txtName.Value
.Offset(RowCount, 1).Value = Me.TXTPRI.Value
.Offset(RowCount, 2).Value = Me.CBODEPARTMENT.Value
.Offset(RowCount, 3).Value = Me.cboPSHCPLEVEL.Value
.Offset(RowCount, 4).Value = DateValue(TXTDEDUCTIONDATE.Value)
.Offset(RowCount, 5).Value = DateValue(TXTCOVERAGEDATE.Value)
End With
Unload Me


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default how to generate date error message

What represents a "wrong" date? Todays date? A specific date? A date tht does
not conform to date format?

" wrote:

I have a user form that works great but I have one last item to fix.
If someone types in a date wrong, it will not update the spreadsheet
with any info and does not give an option to fix the date. What I
would like is an error message and not to update the spreadsheet but
to be able to fix the date. Once that is done, click on OK and then
it can update sheet.
Here is what I have:


Private Sub OK_Click()
Dim RowCount As Long

If Me.txtName.Value = "" Then
MsgBox "Please enter Employee's name", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTPRI.Value = "" Then
MsgBox "Please enter Employee's PRI", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.CBODEPARTMENT.Value = "" Then
MsgBox "Please Choose a Department", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.cboPSHCPLEVEL.Value = "" Then
MsgBox "Please Choose PSHCP Level", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTDEDUCTIONDATE.Value = "" Then
MsgBox "Please Enter a Deducton Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTCOVERAGEDATE.Value = "" Then
MsgBox "Please Enter a Coverage Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
RowCount =
Worksheets("PSHCP").Range("A1").CurrentRegion.Rows .Count
With Worksheets("PSHCP").Range("A1")
.Offset(RowCount, 7).Value = Format(Now, "dd/mmm/yyyy
hh:nn:ss") & Application.UserName
.Offset(RowCount, 0).Value = Me.txtName.Value
.Offset(RowCount, 1).Value = Me.TXTPRI.Value
.Offset(RowCount, 2).Value = Me.CBODEPARTMENT.Value
.Offset(RowCount, 3).Value = Me.cboPSHCPLEVEL.Value
.Offset(RowCount, 4).Value = DateValue(TXTDEDUCTIONDATE.Value)
.Offset(RowCount, 5).Value = DateValue(TXTCOVERAGEDATE.Value)
End With
Unload Me


End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default how to generate date error message

On Feb 15, 4:40*pm, David wrote:
What represents a "wrong" date? Todays date? A specific date? A date tht does
not conform to date format?



" wrote:
I have a user form that works great but I have one last item to fix.
If someone types in a date wrong, it will not update the spreadsheet
with any info and does not give an option to fix the date. *What I
would like is an error message and not to update the spreadsheet but
to be able to fix the date. *Once that is done, click on OK and then
it can update sheet.
Here is what I have:


Private Sub OK_Click()
Dim RowCount As Long


* * If Me.txtName.Value = "" Then
* * * * MsgBox "Please enter Employee's name", vbExclamation,
"PSHCPNUMBERS"
* * * * Me.txtName.SetFocus
* * * * Exit Sub
* * End If
* * If Me.TXTPRI.Value = "" Then
* * * * MsgBox "Please enter Employee's PRI", vbExclamation,
"PSHCPNUMBERS"
* * * * Me.txtName.SetFocus
* * * * Exit Sub
* * End If
* * If Me.CBODEPARTMENT.Value = "" Then
* * * * MsgBox "Please Choose a Department", vbExclamation,
"PSHCPNUMBERS"
* * * * Me.txtName.SetFocus
* * * * Exit Sub
* * End If
* * If Me.cboPSHCPLEVEL.Value = "" Then
* * * * MsgBox "Please Choose PSHCP Level", vbExclamation,
"PSHCPNUMBERS"
* * * * Me.txtName.SetFocus
* * * * Exit Sub
* * End If
* * If Me.TXTDEDUCTIONDATE.Value = "" Then
* * * * MsgBox "Please Enter a Deducton Date", vbExclamation,
"PSHCPNUMBERS"
* * * * Me.txtName.SetFocus
* * * * Exit Sub
* * End If
* * If Me.TXTCOVERAGEDATE.Value = "" Then
* * * * MsgBox "Please Enter a Coverage Date", vbExclamation,
"PSHCPNUMBERS"
* * * * Me.txtName.SetFocus
* * * * Exit Sub
* * End If
* * RowCount =
Worksheets("PSHCP").Range("A1").CurrentRegion.Rows .Count
* * With Worksheets("PSHCP").Range("A1")
* * * * .Offset(RowCount, 7).Value = Format(Now, "dd/mmm/yyyy
hh:nn:ss") & Application.UserName
* * * * .Offset(RowCount, 0).Value = Me.txtName.Value
* * * * .Offset(RowCount, 1).Value = Me.TXTPRI.Value
* * * * .Offset(RowCount, 2).Value = Me.CBODEPARTMENT.Value
* * * * .Offset(RowCount, 3).Value = Me.cboPSHCPLEVEL.Value
* * * * .Offset(RowCount, 4).Value = DateValue(TXTDEDUCTIONDATE.Value)
* * * * .Offset(RowCount, 5).Value = DateValue(TXTCOVERAGEDATE..Value)
End With
* * * * Unload Me


End Sub- Hide quoted text -


- Show quoted text -


A date that does not conform to the date format.
For example, if someon entered 18-18-2008 instead of 18-02-2008 the
date info updated to the spreadsheet would be blank. I am trying to
find a way so that if the date does not match the standard format (dd-
mm-yy or some version of this)to indicate an error and re-type the
date.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default how to generate date error message

Have you tried the VBA function IsDate? Pasted from VBE help:
Returns a Boolean value indicating whether an expression can be converted to
a date.
Syntax

IsDate(expression)

The required expression argument is a Variant containing a date expression
or string expression recognizable as a date or time.

Remarks

IsDate returns True if the expression is a date or is recognizable as a
valid date; otherwise, it returns False. In Microsoft Windows, the range of
valid dates is January 1, 100 A.D. through December 31, 9999 A.D.; the
ranges vary among operating systems

wrote in message
...
On Feb 15, 4:40 pm, David wrote:
What represents a "wrong" date? Todays date? A specific date? A date tht
does
not conform to date format?



" wrote:
I have a user form that works great but I have one last item to fix.
If someone types in a date wrong, it will not update the spreadsheet
with any info and does not give an option to fix the date. What I
would like is an error message and not to update the spreadsheet but
to be able to fix the date. Once that is done, click on OK and then
it can update sheet.
Here is what I have:


Private Sub OK_Click()
Dim RowCount As Long


If Me.txtName.Value = "" Then
MsgBox "Please enter Employee's name", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTPRI.Value = "" Then
MsgBox "Please enter Employee's PRI", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.CBODEPARTMENT.Value = "" Then
MsgBox "Please Choose a Department", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.cboPSHCPLEVEL.Value = "" Then
MsgBox "Please Choose PSHCP Level", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTDEDUCTIONDATE.Value = "" Then
MsgBox "Please Enter a Deducton Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
If Me.TXTCOVERAGEDATE.Value = "" Then
MsgBox "Please Enter a Coverage Date", vbExclamation,
"PSHCPNUMBERS"
Me.txtName.SetFocus
Exit Sub
End If
RowCount =
Worksheets("PSHCP").Range("A1").CurrentRegion.Rows .Count
With Worksheets("PSHCP").Range("A1")
.Offset(RowCount, 7).Value = Format(Now, "dd/mmm/yyyy
hh:nn:ss") & Application.UserName
.Offset(RowCount, 0).Value = Me.txtName.Value
.Offset(RowCount, 1).Value = Me.TXTPRI.Value
.Offset(RowCount, 2).Value = Me.CBODEPARTMENT.Value
.Offset(RowCount, 3).Value = Me.cboPSHCPLEVEL.Value
.Offset(RowCount, 4).Value = DateValue(TXTDEDUCTIONDATE.Value)
.Offset(RowCount, 5).Value = DateValue(TXTCOVERAGEDATE.Value)
End With
Unload Me


End Sub- Hide quoted text -


- Show quoted text -


A date that does not conform to the date format.
For example, if someon entered 18-18-2008 instead of 18-02-2008 the
date info updated to the spreadsheet would be blank. I am trying to
find a way so that if the date does not match the standard format (dd-
mm-yy or some version of this)to indicate an error and re-type the
date.


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
Error message needed if incorrect Date Of Birth (DOB) entered Craig Excel Worksheet Functions 5 January 27th 10 08:24 PM
Date error message (VBA) cdb Excel Programming 3 August 1st 07 07:52 PM
Find Date error message FIRSTROUNDKO via OfficeKB.com Excel Programming 2 September 28th 06 12:28 PM
Adding a date to calender to automatially generate another date? Crystal Long Excel Worksheet Functions 1 January 3rd 06 10:19 PM
Input Date Error Message Dominique Feteau[_2_] Excel Programming 2 December 4th 04 08:00 AM


All times are GMT +1. The time now is 12:49 PM.

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

About Us

"It's about Microsoft Excel"