I don't want a cancel box in an input box

B

BoPeep

Because of problems that are caused if someone hits cancel on an input box, I
need to make it unavailable.
 
T

Terry Kreft

You can't do that unless you roll your own form, what you can do is refuse
to accept the cancel and diplay the inputnbox again.

e.g. Put he following into a module

Function InputBox(Prompt, Optional Title, Optional Default, Optional XPos,
Optional YPos, Optional HelpFile, Optional Context) As String
Dim strRet As String

Do While strRet = vbNullString
strRet = VBA.InputBox(Prompt, Title, Default, XPos, YPos, HelpFile,
Context)
Loop
InputBox = strRet
End Function


Any code you have now which calls the InputBox function should just work.
 
D

Douglas J Steele

I'm not sure it's possible.

What kind of problems are you encountering? Can you not simply put in a
check to ensure that they've provided valid data?
 
B

BoPeep

The message box begins with a quantity of 0 and the message box only pops up
if the quantity is <1. When the cancel button is hit it removes the default
amount of 0 leaving the box empty, so the message box does not pop up again.
I think Terry's solution of looping and refusing to accep the cancel will
take care of the problem if I can just get it properly entered. Thanks!
 
B

BoPeep

I believe that will solve my problem once I get it properly entered. The
message box begins with a quantity of 0 and the message box only pops up if
the quantity is <1. When the cancel button is hit it removes the default
amount of 0 leaving the box empty, so the message box does not pop up again.

Here is my current code:

Private Sub Command5_Click()
Dim cust As String
If Forms!out.Mileage < 1 Then
Forms!out.Mileage = InputBox("We have no mileage for this work order",
"Please Enter Mileage", 0)
End If
cust = Forms!out.[Customer Name]
Forms!out.TOUT = Time()
'Forms!out.Note = Forms!out.Notes
Forms!out.IN = False
Forms!out.BILLABLE = Hour(Time()) - Hour(Forms!out.TIN) + (Minute(Time()) -
Minute(Forms!out.TIN)) / 60
DoCmd.Close acForm, "out"
DoCmd.Close acForm, "I-O"

MsgBox ("You have clocked out of the job for " & cust & " at " &
Format(Time(), "hh:mm"))

End Sub

Would I insert your code after the End If statement? My son wrote this
program for me while he was still in high school. Now his is out on his on
with no internet access and it's sometime hard for him to walk me thru stuff
over the phone. I can do a fair amount of stuff in Access, but am very
limited on my visual basic knowledge. Thanks!
 
B

BoPeep

Actualy I was wondering if it would go in right before "End If", not after

BoPeep said:
I believe that will solve my problem once I get it properly entered. The
message box begins with a quantity of 0 and the message box only pops up if
the quantity is <1. When the cancel button is hit it removes the default
amount of 0 leaving the box empty, so the message box does not pop up again.

Here is my current code:

Private Sub Command5_Click()
Dim cust As String
If Forms!out.Mileage < 1 Then
Forms!out.Mileage = InputBox("We have no mileage for this work order",
"Please Enter Mileage", 0)
End If
cust = Forms!out.[Customer Name]
Forms!out.TOUT = Time()
'Forms!out.Note = Forms!out.Notes
Forms!out.IN = False
Forms!out.BILLABLE = Hour(Time()) - Hour(Forms!out.TIN) + (Minute(Time()) -
Minute(Forms!out.TIN)) / 60
DoCmd.Close acForm, "out"
DoCmd.Close acForm, "I-O"

MsgBox ("You have clocked out of the job for " & cust & " at " &
Format(Time(), "hh:mm"))

End Sub

Would I insert your code after the End If statement? My son wrote this
program for me while he was still in high school. Now his is out on his on
with no internet access and it's sometime hard for him to walk me thru stuff
over the phone. I can do a fair amount of stuff in Access, but am very
limited on my visual basic knowledge. Thanks!
Terry Kreft said:
You can't do that unless you roll your own form, what you can do is refuse
to accept the cancel and diplay the inputnbox again.

e.g. Put he following into a module

Function InputBox(Prompt, Optional Title, Optional Default, Optional XPos,
Optional YPos, Optional HelpFile, Optional Context) As String
Dim strRet As String

Do While strRet = vbNullString
strRet = VBA.InputBox(Prompt, Title, Default, XPos, YPos, HelpFile,
Context)
Loop
InputBox = strRet
End Function


Any code you have now which calls the InputBox function should just work.
 
T

Terry Kreft

When looking at the code window go to the Insert Menu and choose Module.
Copy the code from my original message to the clipboard and then paste it
into the module you've just inserted.
Save the module (it will ask for a name, call it something like modInputBox)


Then that's it your existing code will work as is.


--

Terry Kreft


BoPeep said:
I believe that will solve my problem once I get it properly entered. The
message box begins with a quantity of 0 and the message box only pops up if
the quantity is <1. When the cancel button is hit it removes the default
amount of 0 leaving the box empty, so the message box does not pop up again.

Here is my current code:

Private Sub Command5_Click()
Dim cust As String
If Forms!out.Mileage < 1 Then
Forms!out.Mileage = InputBox("We have no mileage for this work order",
"Please Enter Mileage", 0)
End If
cust = Forms!out.[Customer Name]
Forms!out.TOUT = Time()
'Forms!out.Note = Forms!out.Notes
Forms!out.IN = False
Forms!out.BILLABLE = Hour(Time()) - Hour(Forms!out.TIN) + (Minute(Time()) -
Minute(Forms!out.TIN)) / 60
DoCmd.Close acForm, "out"
DoCmd.Close acForm, "I-O"

MsgBox ("You have clocked out of the job for " & cust & " at " &
Format(Time(), "hh:mm"))

End Sub

Would I insert your code after the End If statement? My son wrote this
program for me while he was still in high school. Now his is out on his on
with no internet access and it's sometime hard for him to walk me thru stuff
over the phone. I can do a fair amount of stuff in Access, but am very
limited on my visual basic knowledge. Thanks!
Terry Kreft said:
You can't do that unless you roll your own form, what you can do is refuse
to accept the cancel and diplay the inputnbox again.

e.g. Put he following into a module

Function InputBox(Prompt, Optional Title, Optional Default, Optional XPos,
Optional YPos, Optional HelpFile, Optional Context) As String
Dim strRet As String

Do While strRet = vbNullString
strRet = VBA.InputBox(Prompt, Title, Default, XPos, YPos, HelpFile,
Context)
Loop
InputBox = strRet
End Function


Any code you have now which calls the InputBox function should just work.
 
T

Terry Kreft

Actually you can forget the code I sent you, just edit your code as follows

change
If Forms!out.Mileage < 1 Then
Forms!out.Mileage = InputBox("We have no mileage for this work order",
"Please Enter Mileage", 0)
End If

To
Do while Forms!out.Mileage < 1
Forms!out.Mileage = InputBox( _
"We have no mileage for this
work order", _
"Please Enter Mileage", 0)
Loop



--

Terry Kreft


BoPeep said:
I believe that will solve my problem once I get it properly entered. The
message box begins with a quantity of 0 and the message box only pops up if
the quantity is <1. When the cancel button is hit it removes the default
amount of 0 leaving the box empty, so the message box does not pop up again.

Here is my current code:

Private Sub Command5_Click()
Dim cust As String
If Forms!out.Mileage < 1 Then
Forms!out.Mileage = InputBox("We have no mileage for this work order",
"Please Enter Mileage", 0)
End If
cust = Forms!out.[Customer Name]
Forms!out.TOUT = Time()
'Forms!out.Note = Forms!out.Notes
Forms!out.IN = False
Forms!out.BILLABLE = Hour(Time()) - Hour(Forms!out.TIN) + (Minute(Time()) -
Minute(Forms!out.TIN)) / 60
DoCmd.Close acForm, "out"
DoCmd.Close acForm, "I-O"

MsgBox ("You have clocked out of the job for " & cust & " at " &
Format(Time(), "hh:mm"))

End Sub

Would I insert your code after the End If statement? My son wrote this
program for me while he was still in high school. Now his is out on his on
with no internet access and it's sometime hard for him to walk me thru stuff
over the phone. I can do a fair amount of stuff in Access, but am very
limited on my visual basic knowledge. Thanks!
Terry Kreft said:
You can't do that unless you roll your own form, what you can do is refuse
to accept the cancel and diplay the inputnbox again.

e.g. Put he following into a module

Function InputBox(Prompt, Optional Title, Optional Default, Optional XPos,
Optional YPos, Optional HelpFile, Optional Context) As String
Dim strRet As String

Do While strRet = vbNullString
strRet = VBA.InputBox(Prompt, Title, Default, XPos, YPos, HelpFile,
Context)
Loop
InputBox = strRet
End Function


Any code you have now which calls the InputBox function should just work.
 
M

mabond

Hi

I'm having a similar problem and wonder why Microsoft have provided two
buttons on an input box which, when it comes to validating data, effectively
perform the same function. I want to capture the cancel event of the input
box and specifically want it to perform differently than the ok event. If
user clicks "cancel" the input box returns a zero-length string. If user
fails to enter data in the input box and clicks "ok" that too returns a
zero-length string and thus I cannot differentiate between the cancel and ok
events when the user fails to enter data in the input box.
MS Excel deals with this by way of an Application.Inputbox method (rather
than an input box function) which allows selective validation of each button
...... why not in Access I wonder?

Michael Bond
 
E

eos

AUTO-REPLY From George Levitt

Please allow this to confirm a system receipt of your e-mail.

I am out of the office until Wednesday morning (1/12/05) and will not be
reviewing or responding to email or voicemail until that time.

I look forward to replying to your message on Wednesday.

Thanks and warmest regards, George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top