473,614 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P erEffort), 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 3015
ac*******@gmail .com wrote in
news:11******** *************@m 79g2000cwm.goog legroups.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.P erEffort), 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.te xt )
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******** *************@m 79g2000cwm.goog legroups.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.P erEffort), 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.te xt )
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
4431
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 the table datingnew the value of the ident field.
1
2487
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 True. I then have an if statement to determine what to write to the screen depending on blnNoData. As long as the if statement is true (doesn't have to go to the else clause), the code runs fine. Otherwise, a type mismatch error is returned. In...
1
2281
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 verify the syntax, and that my .net code is ok - the type mismatch is happening at: DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection) Thanks in advance,
7
15809
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 have a page that allows users to type in the info (actually a calendar pop-up allows me to make sure they do it in the correct format), into a textbox. When this page gets called up again, I want to prefill the box with the existing data, in case...
4
11959
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 14 (STDCOST). ---End Error Msg--- The STDCOST is set to decimal (28,14) and is a formatted in Access as a number, single with 14 decimal. I don't know why I would be getting a Type
3
2909
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 347: 'response.Write(sql2)
1
2800
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 an HTML file. When I execute the EXE, which is only the form, and click the button, I get a "Type Mismatch" error on this line in the form: mailobj.SaveOutlookMessage() Any suggestions on why I'm getting the type mismatch error? --Form code
6
5983
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 class has stuff initialized by calling a sub SetClass that wants some Word specific objects passed-in. If the user mistakingly uses the wrong object, say, uses an Excel object
5
2836
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 each SQL statement using a MsgBox and then input that exact code as a Query in access which works. I'm using Access 97 on Windows XP. My code is below: Dim strKaizen As String strKaizen = "UPDATE KaizenEvents SET(TeamLeader)= '" & & "' WHERE...
19
21550
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 date is more than 10 months out. The query runs fine, but I when I put the criteria of >10 I get 'Data Type mismatch' error. The code below is the original query. I have since put all the datediff bit in code, with all variables declared as date,...
0
8182
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8130
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8433
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7093
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5540
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4052
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.