473,395 Members | 1,774 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,395 software developers and data experts.

Type Mismatch Error

26
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)= '" & [TeamLeader] & "' WHERE ProjectCode=" & [ProjectCode] & " "
DoCmd.RunSQL (strKaizen)

If Nz(Form.AI1) > 0 Then
Dim strActionItems1 As String
strActionItems1 = "INSERT INTO ActionItems (ProjectCode, ActionItem, POC, Status) " & _
"VALUES(" & [ProjectCode] & ",'" & [AI1] & "','" & [POC1] & "'," & [AIStatus1] & ")"
DoCmd.RunSQL (strActionItems1)
End If

If Nz(Form.AI2) > 0 Then
Dim strActionItems2 As String
strActionItems2 = "INSERT INTO ActionItems (ProjectCode, ActionItem, POC, Status) " & _
"VALUES(" & [ProjectCode] & ",'" & [AI2] & "','" & [POC2] & "'," & [AIStatus2] & ")"
DoCmd.RunSQL (strActionItems2)
End If

If Nz(Form.Goal1) > 0 Then
Dim strGoals1 As String
strGoals1 = "INSERT INTO Goals (ProjectCode, Goals, Status) " & _
"VALUES(" & [ProjectCode] & ",'" & [Goal1] & "'," & [GoalStatus1] & ")"
DoCmd.RunSQL (strGoals1)
End If

If Nz(Form.Goal2) > 0 Then
Dim strGoals2 As String
strGoals2 = "INSERT INTO Goals (ProjectCode, Goals, Status) " & _
"VALUES(" & [ProjectCode] & ",'" & [Goal2] & "'," & [GoalStatus2] & ")"
DoCmd.RunSQL (strGoals2)
End If

Dim strTeam As String
strTeam = "INSERT INTO TeamMembers (ProjectCode,TeamMember1,TeamMember2,TeamMember3,T eamMember4,TeamMember5,TeamMember6,TeamMember7,Tea mMember8,TeamMember9,TeamMember10,TeamMember11,Tea mMember12,TeamMember13,TeamMember14) " & _
"VALUES(" & [ProjectCode] & ",'" & [TmMbr1] & "','" & [TmMbr2] & "','" & [TmMbr3] & "','" & [TmMbr4] & "','" & [TmMbr5] & "','" & [TmMbr6] & "','" & [TmMbr7] & "','" & [TmMbr8] & "','" & [TmMbr9] & "','" & [TmMbr10] & "','" & [TmMbr11] & "','" & [TmMbr12] & "','" & [TmMbr13] & "','" & [TmMbr14] & "')"
DoCmd.RunSQL (strTeam)

I know that a mismatch occurs when one is trying to insert the wrong data type into a field. I have checked and rechecked my fields.
Status field = number
ProjectCode = number
Everything else = text

I have three tables that are related by the ProjectCode field. The Kaizen field has an autonumber primary key and the other ProjectCodes are just number fields with duplicates OK. I have this code on a form that will allow a user to input data that will then be sent to the appropriate table. There is a goals table, an action items table, and a team members table as there can be multiple occurrences of these items per unique kaizen event in the main table.

Can anyone spot why I may have a data mismatch error?

Additionally, if you have a suggestion for a better way to write the "Nz(....) >0 piece, that would be good too. I'm basically trying to avoid null and empty cells in the DB.

Thanks in advance
Dec 6 '06 #1
5 2815
nico5038
3,080 Expert 2GB
Is hard to do without the actual code.
In this case I normally place a Break in the code (click in the left rules to get a brown dot) and execute the sub.
When the code halts I use the F8 to step one line after the assign statement of the SQL string.
Then type in the immediate window:
?strSQL
and press [Enter] to get the build SQL.
This I copy/paste in the SQL mode of the query editor and Access will give the error and place the cursor at the erroneous field.
There I correct the statement till it works and then amend the original string.

Nic;o)
Dec 6 '06 #2
kjworm
26
Well, as soon as I posted, I figured out that the "If Nz(Form.AI1) > 0 Then" piece of the code is causing my problems. This requires the "AI1" field to be numeric. If I enter text I get the Type Mismatch Error, but if I enter numbers, everything works fine.

What I am trying to do is create an entry into the DB only if a user populates the form. If the entry field is blank, then nothing will be inserted into the DB. What would be the best way to do this?
Dec 6 '06 #3
nico5038
3,080 Expert 2GB
That's the reason I use for the "empty" check:

IF Len(NZ(field))>0 then ....

This works for both text and numbers being Null or empty.

Nic;o)
Dec 6 '06 #4
kjworm
26
I just replaced the Nz with Len and it works fine. I'll add in what you suggest and take it from there.

Thanks! This answers my question!
Dec 6 '06 #5
nico5038
3,080 Expert 2GB
Glad I could help, success with your application !

Nic;o)
Dec 6 '06 #6

Sign in to post your reply or Sign up for a free account.

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...
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...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
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...
1
by: jodyblau | last post by:
I have a database which works fine until I create and MDE file. Once I create the MDE, when I open a particular form I get a "Type Mismatch" error. Because its an MDE file, I can't step through...
19
by: zz12 | last post by:
Hello, is there a setting in IIS 5.0 that would quickly fix the following error?: Microsoft VBScript runtime (0x800A000D) Type mismatch It's strange because some of our .asp pages were...
1
by: nckinfutz | last post by:
hello, I am having a problem with an access database. this is not my database and I did not create it, nor am I very good at access. however, I am a network engineer and that is why this problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.