PDA

View Full Version : [SOLVED:] type mismatch running excel code in access runtime - accdb works - 2007



GerryS
09-30-2015, 03:16 AM
My workplace has just upgraded from XP and Office 2003 to W7 and Office 2007 - no comment!. Some years ago, I created an Access db to record quality control data. One thing it does is import data from remote labs presented in xl. The following code worked with Office 2003 and Access runtime (there is a backend database with users accessing it through an Access runtime application which I distribute:-
...
Dim oXLData As Excel.Workbook, oXLApp As Excel.Application
Dim oXLEntry As Excel.Worksheet, oXLNames As Excel.Worksheet
Dim raSources As Excel.Range, raSitesUnScr As Excel.Range
...
oXLNames.Activate
oXLNames.Range(oXLNames.Cells(7, 2), oXLNames.Cells(7, 2)).Select
oXLNames.Range(oXLApp.Selection, oXLApp.Selection.End(xlDown)).Select
Set raSitesUnScr = oXLApp.Selection

This still works with Access 2007 on my pc with the full Access, but falls over with a type mismatch on last line (Set raSitesUnScr =...) when packaged with runtime and run on other machines. There are 2 similar blocks of code which start at a specified cell and create ranges extending to first blank cell. I tracked it down with lots of msgbox's - not easy debugging with runtime:(. The code eventually continues with
For Each clSite In raSources
I'm sure there are other ways of doing this, but it feels like defeat to just abandon this one, especially if there is a risk of going right thru to a new runtime before finding more problems!
Referenced libraries are:- VBA; Access 12.0 Object; Office 12.0 Object; Office 12.0 db engine Object & Excel 12.0 Object
Any ideas why and how to get round?

SamT
09-30-2015, 08:53 AM
Dim oXLData As Excel.Workbook, oXLApp As Excel.Application
Dim oXLEntry As Excel.Worksheet, oXLNames As Excel.Worksheet
Dim raSources As Excel.Range, raSitesUnScr As Excel.Range
'''
oXLNames.Activate
Set raSitesUnScr = oXLNames.Range(Cells(7, 2), Cells(7, 2).End(xlDown))

GerryS
10-02-2015, 03:35 AM
Thanks SamT. Embarrassingly simple. Generally, is it my imagination, or is A2007 runtime stricter with types than the the full version?