Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default What is wrong with this?

Hello all,

Here is my code:



Public Sub EnterTime()
Dim pdteInputBox As Date

gintMsgBoxResponse = MsgBox("The current time is: " _
& Format(Time, "h:mm AM/PM") & "." & vbCrLf & vbCrLf _
& "Would you like to enter this time?", vbQuestion + _
vbYesNo, "Current Time")

If gintMsgBoxResponse = vbYes Then
ActiveCell.Value = Time
Else
pdteInputBox = TimeValue(InputBox("Please enter the correct
time.", _
"Time", Format(Time, "h:mm AM/PM")))

If pdteInputBox = "" Then
Exit Sub
Else
ActiveCell.Value = pdteInputBox
End If
End If

gintMsgBoxResponse = 0
End Sub




The problem I'm having is if I answer "No" to the message box and then
enter a time (9:03) in the input box and hit "OK", I get a "Run-time
error '13': Type mismatch".

I also noticed that I got the same error when I hit "Cancel" on the
input box.

Any help would be greatly appreciated,

Conan Kelly


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default What is wrong with this?

try changing

If pdteInputBox = "" Then


to


If pdteInputBox = 0 Then


--
Regards,
Tom Ogilvy


"Conan Kelly" <CTBarbarin at msn dot com wrote in message
...
Hello all,

Here is my code:



Public Sub EnterTime()
Dim pdteInputBox As Date

gintMsgBoxResponse = MsgBox("The current time is: " _
& Format(Time, "h:mm AM/PM") & "." & vbCrLf & vbCrLf _
& "Would you like to enter this time?", vbQuestion + _
vbYesNo, "Current Time")

If gintMsgBoxResponse = vbYes Then
ActiveCell.Value = Time
Else
pdteInputBox = TimeValue(InputBox("Please enter the correct
time.", _
"Time", Format(Time, "h:mm AM/PM")))

If pdteInputBox = "" Then
Exit Sub
Else
ActiveCell.Value = pdteInputBox
End If
End If

gintMsgBoxResponse = 0
End Sub




The problem I'm having is if I answer "No" to the message box and then
enter a time (9:03) in the input box and hit "OK", I get a "Run-time
error '13': Type mismatch".

I also noticed that I got the same error when I hit "Cancel" on the
input box.

Any help would be greatly appreciated,

Conan Kelly




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default What is wrong with this?

Try

If CStr(pdteInputBox) = "" Then
.....

You might think about skipping the first messagebox and just always popping
up the input with the current time pre-filled.
It's less code, just as quick for your user as your "two-pronged" approach,
and minimizes the number of different UI prompts the user has to get used
to.

Tim


--
Tim Williams
Palo Alto, CA


"Conan Kelly" <CTBarbarin at msn dot com wrote in message
...
Hello all,

Here is my code:



Public Sub EnterTime()
Dim pdteInputBox As Date

gintMsgBoxResponse = MsgBox("The current time is: " _
& Format(Time, "h:mm AM/PM") & "." & vbCrLf & vbCrLf _
& "Would you like to enter this time?", vbQuestion + _
vbYesNo, "Current Time")

If gintMsgBoxResponse = vbYes Then
ActiveCell.Value = Time
Else
pdteInputBox = TimeValue(InputBox("Please enter the correct
time.", _
"Time", Format(Time, "h:mm AM/PM")))

If pdteInputBox = "" Then
Exit Sub
Else
ActiveCell.Value = pdteInputBox
End If
End If

gintMsgBoxResponse = 0
End Sub




The problem I'm having is if I answer "No" to the message box and then
enter a time (9:03) in the input box and hit "OK", I get a "Run-time
error '13': Type mismatch".

I also noticed that I got the same error when I hit "Cancel" on the
input box.

Any help would be greatly appreciated,

Conan Kelly




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default What is wrong with this?

Tom,

Thanks. That solved the first problem. But I'm still getting the
error message if I hit "Cancel" on the input box.

Thanks again for the help,

Conan




"Tom Ogilvy" wrote in message
...
try changing

If pdteInputBox = "" Then


to


If pdteInputBox = 0 Then


--
Regards,
Tom Ogilvy


"Conan Kelly" <CTBarbarin at msn dot com wrote in message
...
Hello all,

Here is my code:



Public Sub EnterTime()
Dim pdteInputBox As Date

gintMsgBoxResponse = MsgBox("The current time is: " _
& Format(Time, "h:mm AM/PM") & "." & vbCrLf & vbCrLf _
& "Would you like to enter this time?", vbQuestion + _
vbYesNo, "Current Time")

If gintMsgBoxResponse = vbYes Then
ActiveCell.Value = Time
Else
pdteInputBox = TimeValue(InputBox("Please enter the correct
time.", _
"Time", Format(Time, "h:mm AM/PM")))

If pdteInputBox = "" Then
Exit Sub
Else
ActiveCell.Value = pdteInputBox
End If
End If

gintMsgBoxResponse = 0
End Sub




The problem I'm having is if I answer "No" to the message box and
then
enter a time (9:03) in the input box and hit "OK", I get a
"Run-time
error '13': Type mismatch".

I also noticed that I got the same error when I hit "Cancel" on the
input box.

Any help would be greatly appreciated,

Conan Kelly






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default What is wrong with this?

Public Sub EnterTime()
Dim pdteInputBox As Date

gintMsgBoxResponse = MsgBox("The current time is: " _
& Format(Time, "h:mm AM/PM") & "." & vbCrLf & vbCrLf _
& "Would you like to enter this time?", vbQuestion + _
vbYesNo, "Current Time")

If gintMsgBoxResponse = vbYes Then
ActiveCell.Value = Time
Else
On Error Resume Next
pdteInputBox = TimeValue(InputBox("Please enter the correct time.",
_
"Time", Format(Time, "h:mm AM/PM")))
On Error goto 0
If pdteInputBox = 0 Then
Exit Sub
Else
ActiveCell.Value = pdteInputBox
End If
End If

gintMsgBoxResponse = 0
End Sub

--
Regards,
Tom Ogilvy


"Conan Kelly" <CTBarbarin at msn dot com wrote in message
...
Tom,

Thanks. That solved the first problem. But I'm still getting the
error message if I hit "Cancel" on the input box.

Thanks again for the help,

Conan




"Tom Ogilvy" wrote in message
...
try changing

If pdteInputBox = "" Then


to


If pdteInputBox = 0 Then


--
Regards,
Tom Ogilvy


"Conan Kelly" <CTBarbarin at msn dot com wrote in message
...
Hello all,

Here is my code:



Public Sub EnterTime()
Dim pdteInputBox As Date

gintMsgBoxResponse = MsgBox("The current time is: " _
& Format(Time, "h:mm AM/PM") & "." & vbCrLf & vbCrLf _
& "Would you like to enter this time?", vbQuestion + _
vbYesNo, "Current Time")

If gintMsgBoxResponse = vbYes Then
ActiveCell.Value = Time
Else
pdteInputBox = TimeValue(InputBox("Please enter the correct
time.", _
"Time", Format(Time, "h:mm AM/PM")))

If pdteInputBox = "" Then
Exit Sub
Else
ActiveCell.Value = pdteInputBox
End If
End If

gintMsgBoxResponse = 0
End Sub




The problem I'm having is if I answer "No" to the message box and
then
enter a time (9:03) in the input box and hit "OK", I get a
"Run-time
error '13': Type mismatch".

I also noticed that I got the same error when I hit "Cancel" on the
input box.

Any help would be greatly appreciated,

Conan Kelly








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
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
What am I doing wrong? PFB1033 Excel Discussion (Misc queries) 1 February 13th 06 02:13 AM
What's Wrong? Pam Excel Programming 2 September 24th 04 07:10 PM
What is wrong in this Sub? Michael[_27_] Excel Programming 3 August 18th 04 06:46 PM
What do i wrong here Dick Kusleika[_3_] Excel Programming 0 August 11th 04 08:40 PM


All times are GMT +1. The time now is 10:33 PM.

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"