Cancelling InputBox procedure

navi95

Registered User.
Local time
Today, 02:32
Joined
Jan 3, 2013
Messages
59
!WARNING! I am using Access in German so you will notice some strange words written in the code :)

Hi Guys,

So I have a button with the following vba code which runs when the button has been clicked on:

Private Sub Umschaltfläche15_Click()
TempVars.Add "bestnr", InputBox("Bestellnummer Eingeben")
DoCmd.OpenForm "retour"
End Sub

This works great but when I want to cancel/close the input box which appears I get a message that the script has ended etc and if I want to close or debug etc, I would like to remove this pop up from appearing.

I tried setwarnings to false, that didnt help.

Any thoughts? Thanks! :)
 
..but when I want to cancel/close the input box which appears I get a message that the script has ended etc and if I want to close or debug etc, ..
I can't reproduce that error.
Try to create a new form and put in the same code behind a button, do you still get the same error, if yes post a sample database, with the form in it.
 
I can't reproduce that error.
Try to create a new form and put in the same code behind a button, do you still get the same error, if yes post a sample database, with the form in it.

2b036b480c.jpg


So that pops up when I choose to cancel on the input window. I think its like an unexpected end to the script, right?

If this doesnt help I'll upload the database
 
As I wrote before I can't reproduce that error.
Try it in the attached database.
 

Attachments

Understand that when you cancel an Input box, you are supplying a null answer to the question and will have to handle TWO conditions: First, an abnormal program event; and second, an abnormal answer to the question implied in the input box.

What I sometimes do to stop errors cold is

Code:
    On Error Resume Next
   [I] something that I want to protect from all traps[/I]
    On Error GoTo 0   (or GoTo MyTrapHandler)

This MIGHT stop the trap but you would still have to write defensive code for the (non-)value that gets returned from the InputBox call.

I use that trap protector most often when I am already taking an error path out of some code and I have a common exit routine that closes every object. I protect the code sequence that closes things that might not have been open at the time, but for the error exit case, I don't care, it is an attempt at an orderly emergency shutdown. But in that context, I get no traps even if the recordsets and application objects weren't open at the time. So it MIGHT work for you.
 
I presume something like this

Code:
dim entered as string

entered  = InputBox("Bestellnummer Eingeben")
if entered<>"" then
      TempVars.Add "bestnr", entered
      docmd.OpenForm "retour"
end if
End Sub
 
Hey guys,

thanks for all of your input but when I ran the database on the intended PC for testing purposes, I could cancel the input box without any dialogues popping up.
Strange...but whatever lol :)

Regards,

Navi
 
As I wrote before I can't reproduce that error.
Try it in the attached database.

I tried it with the database you posted up, I couldnt get the same error there either. No idea why to be honest.
 

Users who are viewing this thread

Back
Top Bottom