Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VbOKCancel, but Cancel doesn't cancel?

Status
Not open for further replies.

flaviooooo

Programmer
Feb 24, 2003
496
0
0
FR
Hi,

I have a form with a button. When you press the button it asks for a number, and that's the number of times a document will be printed. It works when I enter a value and press OK, but when I press Cancel it gives me an error: Type Mismatch

Here's the code:
Dim aantal, teller As Integer
Dim MyApp As LabelManager2.Application
Dim MyDoc As LabelManager2.Document
Dim var As LabelManager2.Variable

aantal = InputBox("How many labels?", "Labels", 0, vbOKCancel)

Set MyApp = New LabelManager2.Application
MyApp.Visible = False
Set MyDoc = MyApp.Documents.Open("C:\Program Files\CS6\Lab\GrondstoffenLeeg.Lab")
teller = 0

Do While teller < aantal '<--- here's where the error points
MyDoc.PrintDocument 2
teller = teller + 1
Loop

MyApp.Documents.CloseAll True
MyApp.Quit
Set MyApp = Nothing
 
Remember, InputBox returns a string value. You're then loading that string (or trying to, at any rate) into an integer variable.

I think the function you want is MsgBox; it doesn't allow user input, other than Clicking the specified buttons, then it returns a numeric value.
 
I agree with RJFrost, but in order to get your QTY of labels you will need to use your InputBox or a form to specify a QTY. You should be able to make aantal variable a string/variant rather than a integer and write something like this

if aantal = vbCancel then
Exit Sub
End if


Max1mum.
- VBA Programmer
- Studying for MCSD
 
Good point; looks like you'd want something like

If aantal = vbCancel Then
Exit Sub
Else
<do loop code>
End If
 
Thanks for the help guys, but this doesn't seem to work.

In the meantime I had found out that it places &quot;&quot; into aantal.

So I had just made an:

if aantal = &quot;&quot; then

else
<code>
end if

It works now :)
 
Better practice would be

if aantal <> &quot;&quot; then
<code>
end if

It's just easier to read, and makes a bit more sense.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
I've still got a philosophical twitch at loading a string (empty or no) into an integer, but as long as it gets the job done...
 
myMonth = InputBox(&quot;Enter Month. ex: June, 2000&quot;, &quot;Monthly Report&quot;, &quot;September, 2003&quot;)

If IsNull(myMonth) Then
Exit Sub
Else

I've had the same issue with people clicking cancel on a report that required a date. Try this.

Randall Vollen
National City Bank Corp.

Just because you have an answer - doesn't mean it's the best answer.
 
Let's not get overly philosophical guys. Here's what the documentation says:

[tt]
If the user clicks OK or presses ENTER , the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string (&quot;&quot;).
[/tt]

You just have to check for an empty string.

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top