Solved

Run-time error 13 type mismatch

Posted on 2013-01-15
10
597 Views
Last Modified: 2013-01-17
Getting the error Run-time error 13 type mismatch on the following line of code

Set CBEDSRst = CurrentDb.OpenRecordset("Select Distinct RecType, CBEDSCourse from [" & TblNmStr & "] WHERE RecType='C' and CrsType='" & CTypeArr(CTypeLpCnt) & "' " & PTCritArr(PTypeLpCnt))
0
Comment
Question by:needhelpfast569
  • 4
  • 3
  • 3
10 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38780896
what is the Data Type of field CrsType ?

if number

try this

Set CBEDSRst = CurrentDb.OpenRecordset("Select Distinct RecType, CBEDSCourse from [" & TblNmStr & "] WHERE RecType='C' and CrsType=" & CTypeArr(CTypeLpCnt) & " & PTCritArr(PTypeLpCnt))

or this

Set CBEDSRst = CurrentDb.OpenRecordset("Select Distinct RecType, CBEDSCourse from [" & TblNmStr & "] WHERE RecType='C' and CrsType=" & CTypeArr(CTypeLpCnt)  & PTCritArr(PTypeLpCnt))

what does the function "CTypeArr" do ?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38780903
Try added a debug .print to write your query string to the immediate window.  Is the query string what you are expecting?

If not, copy and paste it in your next comment.

Also, what is the datatype of the CrsType field?
And is TblNmStr a string variable or the name of an actual table?

Dim strSQL as string
strSQL = "Select Distinct RecType, CBEDSCourse from [" & TblNmStr &  "] WHERE RecType='C' and CrsType='" & CTypeArr(CTypeLpCnt) & "' " & PTCritArr(PTypeLpCnt))
debug.print strSQL
Set CBEDSRst = CurrentDb.OpenRecordset(strSQL)

Open in new window

0
 

Author Comment

by:needhelpfast569
ID: 38780928
Hi Capricorn1,

Both of the fields are numbers

the compiler did not like the line dropping those chracters ' and " added the editing back in and the compiler accepted the line again

what is strange is I have an access 2003 version of the program and this line works but having the problem with same line in the Access 2007 version
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38780939
what does this two function do

CTypeArr(CTypeLpCnt)  

 PTCritArr(PTypeLpCnt)


can you upload a copy of the db?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38780947
needhelpfast -

You might have missed my comment earlier.

Is TblNmStr a string variable or the name of an actual table?

If it is an actual table name, try this:

Dim strSQL as string
strSQL = "Select Distinct RecType, CBEDSCourse from  [TblNmStr] WHERE RecType='C' and CrsType=" & CTypeArr(CTypeLpCnt) &  PTCritArr(PTypeLpCnt))
debug.print strSQL
Set CBEDSRst = CurrentDb.OpenRecordset(strSQL)

Open in new window


The debug.print strSQL line will write the query string to the debugger window.

If you copy/paste it here, it will give us a better idea of where your query is going wrong.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38780985
<what is strange is I have an access 2003 version of the program and this line works but having the problem with same line in the Access 2007 version >

so the line works in A2003,

open your VBA window, then
Tools > References

see if you have a reference with "MISSING" prefix
uncheck and select the available version

Do a DEBUG > COMPILE

make sure that all errors raised is corrected
0
 

Author Comment

by:needhelpfast569
ID: 38781065
The references look good
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 38781069
upload a copy of the db
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38781071
Ok - I'm going to click "unmonitor" here and leave this to cap1 - very difficult to help if you don't respond to the comments posted.
0
 

Author Closing Comment

by:needhelpfast569
ID: 38787523
problem was a reference out of order
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running sum query 6 25
Access 2010 db.Execute using dbFailOnError and dbSeeChanges 10 47
Sub Reports 8 21
how to link subforms ms/access VBA 6 26
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

929 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now