By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Type Mismatch

P: n/a
Hi All,

I dont know what I am doing wrong. Why does this give me a Type
Mismatch error:

I have EffSalary defined as Currency in table and form
PerEffort as Number in Table, and General Number on the form

I have this code in Lost Focus for PerEffort:

Me.EffSalary = IIf(IsNull(Me.PerEffort), 0, ((Me.BaseSalary *
Me.PerEffort) / 100))

It works fine if the user enters something in PerEffort, but when I
leave it blank, it gives me a type mismatch error.
I have tried many variations of the above code, using nz, using
variables, etc. but cant seem to figure out what is wrong.
How do I achieve that funnctionality: Basically, I want to be able to
calculate EffSalary by multiplying BaseSalary with PerEffort, but the
user can leave PerEffort blank for now, until they hit the save button,
but the Lost Focus fires sooner than that.

Many thanks for the help.
Puneet.

Aug 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ac*******@gmail.com wrote in
news:11*********************@m79g2000cwm.googlegro ups.com:
Hi All,

I dont know what I am doing wrong. Why does this give me a
Type Mismatch error:

I have EffSalary defined as Currency in table and form
PerEffort as Number in Table, and General Number on the form

I have this code in Lost Focus for PerEffort:

Me.EffSalary = IIf(IsNull(Me.PerEffort), 0,
((Me.BaseSalary *
Me.PerEffort) / 100))

It works fine if the user enters something in PerEffort, but
when I leave it blank, it gives me a type mismatch error.
I have tried many variations of the above code, using nz,
using variables, etc. but cant seem to figure out what is
wrong. How do I achieve that funnctionality: Basically, I want
to be able to calculate EffSalary by multiplying BaseSalary
with PerEffort, but the user can leave PerEffort blank for
now, until they hit the save button, but the Lost Focus fires
sooner than that.

Many thanks for the help.
Puneet.
Why: IIF evaluates both options, then returns the value of the
condition. leaving PerEffort blank may give a null or an empty
string, which throws up the error before evaluating the IsNull.

Try:
dim iPerEffort as integer.
iPerEffort = cInt("0" & me.perEffort.text )
Me.EffSalary = Me.BaseSalary *iPerEffort/100

Or: set a default value of 0 for Me.PerEffort
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 14 '06 #2

P: n/a
Thanks Bob.
I have the default value as 0, but have to account for the situation
that the user deletes the 0 and tabs out of the field.

The CInt trick worked like a charm.

You are great!

Bob Quintal wrote:
ac*******@gmail.com wrote in
news:11*********************@m79g2000cwm.googlegro ups.com:
Hi All,

I dont know what I am doing wrong. Why does this give me a
Type Mismatch error:

I have EffSalary defined as Currency in table and form
PerEffort as Number in Table, and General Number on the form

I have this code in Lost Focus for PerEffort:

Me.EffSalary = IIf(IsNull(Me.PerEffort), 0,
((Me.BaseSalary *
Me.PerEffort) / 100))

It works fine if the user enters something in PerEffort, but
when I leave it blank, it gives me a type mismatch error.
I have tried many variations of the above code, using nz,
using variables, etc. but cant seem to figure out what is
wrong. How do I achieve that funnctionality: Basically, I want
to be able to calculate EffSalary by multiplying BaseSalary
with PerEffort, but the user can leave PerEffort blank for
now, until they hit the save button, but the Lost Focus fires
sooner than that.

Many thanks for the help.
Puneet.
Why: IIF evaluates both options, then returns the value of the
condition. leaving PerEffort blank may give a null or an empty
string, which throws up the error before evaluating the IsNull.

Try:
dim iPerEffort as integer.
iPerEffort = cInt("0" & me.perEffort.text )
Me.EffSalary = Me.BaseSalary *iPerEffort/100

Or: set a default value of 0 for Me.PerEffort
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com
Aug 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.