[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

problem with Nz on microsoft access 2013 vba

Posted on 2014-02-12
4
Medium Priority
?
948 Views
Last Modified: 2014-02-12
hi

i have a code like this

Dim QtyL As integer
QtyL = Nz(InputBox("please enter a number"), 0)

Open in new window


but when i don't add  any number on the inputbox i get an error "type mismatch" do the NZ function dont has to handle it and replace the NULL with a ZERO? so why i get an error message
0
Comment
Question by:bill201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 58
ID: 39854208
Type mis-match means your using a string for a numeric, or a numeric for a string.

The input box returns a string and your trying to place it in a variable that's an integer.

What you want is:

Dim QtyL As integer
QtyL = CInt(Nz(InputBox("please enter a number"), 0))

It's also a good idea to prefix variables:

int = Integer
lng = Long
str = string
var = variant

etc.

Jim.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 39854231
BTW, the other thing is that a NULL and a zero-length string are not one in the same thing, so your going to want something like this:

Dim varRet as Variant
Dim intQtyL as Integer

varRet = InputBox("please enter a number")

If NZ(varRet,0)<>"" then
    intQtyL = CInt(varRet)
Else
   Msgbox "You didn't enter a number"
End If

Jim.
0
 

Author Closing Comment

by:bill201
ID: 39854326
Many thanks for the reply, I am very grateful to you, I wish there was an option to give more than five hundred points :)
0
 
LVL 58
ID: 39854345
I'm simply glad to help and appreciate the thanks.

Jim.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New style of hardware planning for Microsoft Exchange server.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question