Type Mismatch

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,099
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I'm using my workbook on a new Win 11 machine and getting a Type Mismatch error in many functions.

It's where a recordset record count is assigned to an integer. I've uploaded a image that may show it.
When hovering over Record Count there's a symbol char at the end.
I think it's a Win 11 thing but not sure.
Has the datatype for recordCount changed ?
 

Attachments

  • 100_2461.jpg
    100_2461.jpg
    167.2 KB · Views: 14

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I'm not familiar with the specifics of working with this type of SQL query but I have a recommendation that you use Option Explicit, and declare every variable with a data type, include procedure arguments. I'm not sure that is related to your problem but it often uncovers bugs. rx is not declared in this function, so I don't know if it's declared anywhere. It seems to be doing what you expect, though, otherwise you would get an error on .Open. How is rx typed and set? I would be interested in looking at the spec for it.

To further diagnose this I would add
VBA Code:
Debug.Print TypeName(rx.RecordCount)
and see if it comes back as String, or a numeric type.

The code you are showing here does not assign RecordCount to an integer. I recommend you copy all of your code and paste it into a post. For readability, select the code after pasting and click "VBA" in the edit controls to add CODE tags.
 
Upvote 0
Thanks Jeff, your typename suggestion showed it as LongLong (which I'd never heard of).
And it's happy as that, although before I found out I'd changed them all to Cint(rx.recordcount) which also worked.
I should have added it's 64 bit Excel, may be something to do with it. (I do use Option Explicit)
rx is set in the module declarations as Public rx as ADODB.Recordset and I connect to Access with various sql queries.
Also Public cnn as ADODB.connection and Refs needed for Microsoft Activex Data Objects 2.8 Library

VBA Code:
Sub SetBackend()
On Err GoTo Done
Set cnn = New ADODB.Connection
Set rx = New ADODB.Recordset
OpenBackend
Done:
End Sub
Sub OpenBackend() 'Access
Dim tPath$
  tPath = GetPath(ThisWorkbook.FullName)
        cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & tPath & "BackendII.mdb"
cnn.Open
End Sub
 
Upvote 0
LongLong is a 64-bit integer, valid only on 64-bit Excel installs. It is possible that RecordCount was Long in 32-bit, and LongLong in 64-bit. But unless you recently upgraded from 32- to 64-bit I would not expect this issue to just pop up suddenly.

What I did not know until just now is that if you write code with a caret "^" at the end of a number, it types it as LongLong. I could have saved us a step if I had known that, but I've never had to deal with number bigger than Long.

Forced coercion with Cint will work fine as long as you have a record count under 2,147,483,647 :)
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top