473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Type Mismatch

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
2 2988
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Arun Wadhawan | last post by:
Hello MY SQL Server is causing me this problem : Microsoft VBScript runtime error '800a000d' Type mismatch: 'ident' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I am getting from...
1
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to...
1
by: Mark | last post by:
Hi - I tried this in VS.Net, and also in the Web Matrix code below: - but I am getting a type mismatch error. The sql statement runs perfectly from within the Access Query Designer. Can anyone...
7
by: middletree | last post by:
I've been messing with this for hours, and have been to various sites, including Aaron's site, and am truly stumped. The short version: in SQL Server, the 4 fields in question are datetime. I...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
3
by: amitbadgi | last post by:
I am getting teh following error while converting an asp application to asp.net, Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. Source Error: Line...
1
by: Brett | last post by:
I have a form that calls a method within a DLL. By clicking a button on the form, the DLL is instantiated and the SaveOutlookMessage() method invoked. The DLL code copies messages from Outlook to...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
5
by: kjworm | last post by:
Hello Everyone, I have been fighting with a type mismatch error for many hours today and I can't seem to find what the problem is. Hopefully it is more than a missing apostrophe! I have isolated...
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.