Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2005, 10:40 AM
Authorized User
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default OpenRecordset And Run-Time Error 13 Type Mismatch

Hi,
I have some VBA in a form.

I open a table on one line with

Set MyCorrCos = MyDb.OpenRecordset("Correl_Cos", DB_OPEN_TABLE)

and it works fine, but a different table in an identical way

Set MyCorrData = MyDb.OpenRecordset("CorrelCoef", DB_OPEN_TABLE)

Produces Run-Time Error 13 Type Mismatch

Can anyone explain why? I've run out of ideas! I'm using Access XP. A cut down coding is below:

Thanks

Andrew


Private Sub Button1_Click()
'On Error GoTo Err_Button1_Click
Dim MyWksp As Workspace, MyDb As Database
Dim MySSTab, RetRS, MyCoListing, MyCorrCos, MyCorrData As Recordset
Set MyWksp = DBEngine.Workspaces(0) ' Get default workspace.
Set MyDb = MyWksp.Databases(0) ' Get current database.
Set MySSTab = MyDb.OpenRecordset("Start_Stop_Co", DB_OPEN_TABLE)

Set MyCoListing = MyDb.OpenRecordset("Correl_Cos", DB_OPEN_TABLE) 'Open Table with Co's
Set MyCorrCos = MyDb.OpenRecordset("Correl_Cos", DB_OPEN_TABLE) 'Open Table with Co's

Set MyCorrData = MyDb.OpenRecordset("CorrelCoef", DB_OPEN_TABLE)

DoEvents
MyWksp.BeginTrans ' Start of transaction.
'Tidy Up

MySet.Close
Set MySSTab = Nothing
Set MyCoListing = Nothing
Set MyCorrCos = Nothing
Set MyCorrData = Nothing
Set MyWksp = Nothing
Set MyDb = Nothing

Button0.Caption = "&Close"
Button1.Enabled = True
DoEvents

Exit_Button1_Click:
    Exit Sub

Err_Button1_Click:
    MsgBox Error$
    Resume Exit_Button1_Click

End Sub
 
Old March 22nd, 2005, 11:57 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When you dimension a set of variables
Code:
    Dim A, B, C, D As Recordset
A, B and C are Variants; only D is a recordset. (This has been changed in .NET, finally!)

Explicitly Dim each variable:
Code:
    Dim MySSTab     As Recordset
    Dim RetRS       As Recordset
    Dim MyCoListing As Recordset
    Dim MyCorrCos   As Recordset
    Dim MyCorrData  As Recordset
 
Old March 22nd, 2005, 12:17 PM
Authorized User
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian

thanks for the posting. I've done as you suggested, but rather than having the runtime error on the last one in the list MyCorrData, I now have it on the first MySSTab. I think this is something to do with the use of ADO in recordsets, see:

http://p2p.wrox.com/topic.asp?TOPIC_...+type+mismatch

I've reconfigured it to

Dim Cnn1 As ADODB.Connection
Set Cnn1 = CurrentProject.Connection

Set MyCoListing = New ADODB.Recordset 'Open Table with Co's
Set MyCorrCos = New ADODB.Recordset 'Open Table with Co's
Set MyCorrData = New ADODB.Recordset
Set RetRS = New ADODB.Recordset

MyCoListing.Open "Correl_Cos", Cnn1, , , adCmdTable 'Open Table
MyCorrCos.Open "Correl_Cos", Cnn1, , , adCmdTable 'Open Table
MyCorrData.Open "CorrelCoef", Cnn1, , , adCmdTable 'Open Table

I'm currently struggling with the line

MySQLSt = "SELECT FieldX etc.. My Query string"
Set RetRS = MyDb.OpenRecordset(MySQLSt)

which produces an error 424: Object Required. If you have any thoughts about this I'd be most grateful

Thanks

Andrew

 
Old March 22nd, 2005, 12:31 PM
Authorized User
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, that should have been


MySQLSt = "SELECT FieldX etc.. My Query string"
RetRS.Open (MySQLSt), Cnn1, , , adCmdTable

rather than

MySQLSt = "SELECT FieldX etc.. My Query string"
Set RetRS = MyDb.OpenRecordset(MySQLSt)

with runtime error

'-2147217900 (80040e14)'
Syntax Error in FROM Clause

Thanks

Andrew


 
Old March 22nd, 2005, 01:19 PM
Authorized User
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, it needs to be

RetRS.Open (MySQLSt), Cnn1, , , adCmdQuery

not

RetRS.Open (MySQLSt), Cnn1, , , adCmdTable

 
Old March 22nd, 2005, 05:20 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

So it's working now?





Similar Threads
Thread Thread Starter Forum Replies Last Post
getting runtime error 13: type mismatch rita9 Beginning VB 6 2 March 14th, 2008 04:36 AM
Error Number 13 : Type Mismatch ryoga_7482 BOOK: Expert Access 2007 Programming ISBN 978-0-470-17402-9 2 January 31st, 2008 02:20 AM
Why am I getting Runtime Error 13: Type Mismatch? dan_thorman Excel VBA 1 January 24th, 2007 02:06 PM
run-time error 13: type mismatch bryan.lugo Excel VBA 2 April 19th, 2006 04:39 AM
Error 13 Type Mismatch lguzman Access VBA 2 January 6th, 2005 10:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.