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

Version Angst

124 100+
I have a database that is opened by users with different versions of Access. The reference to MS Excel 15.0 shows up after an Office 2013 user has opened it and the database will not open in earlier versions of Access afterwards until I changed the Excel reference back to an earlier version. I have tried to change all references to Excel in the code to be late binding:

Expand|Select|Wrap|Line Numbers
  1. Function OpenExcel(strFileName As String)
  2. Dim xl  As Object
  3.  
  4. Dim WKB As New Excel.Workbook
  5.  
  6.     Set xl = CreateObject("Excel.Application")
  7.     xl.Visible = True
  8.     Set WKB = xl.Workbooks.Open(strFileName)
  9.     Set xl = Nothing
  10.     Set WKB = Nothing
  11.  
  12. End Function
  13.  
This code is just a sample. There are hundreds of references to Excel in the project. That does not seem to make any difference. Is there some way of late binding Excel so that it won't make it change the reference to Excel 15.0 or some workaround to deal with users who have 2007, 2010 and 2013? Any advice is much appreciated.
Sep 15 '15 #1
6 1018
MikeTheBike
639 Expert 512MB
Hi

Looking at the sample coder you still seem to be early binding as you have a variable declared as Excel.Workbook.

If you do not get a compile error then it would seem you also have reference set to the Excel object library. This will need removing. Any references to the Excel library will then cause a compile error and you can then change the variable to an Object type.

However this does impose a strict discipline requiring you to explicitly refer to the Excel application's object, properties and methods.

ie

XlApp.Cells(1,2)= "some value"

I never use early binding in Access when automation Excel.

HTH


MTB
Sep 16 '15 #2
jforbes
1,107 Expert 1GB
To program Excel with Late Binding, MikeTheBike has you covered:
  1. Remove all references to Office
  2. Declare your variables as Objects

Late Binding works just fine, but you'll loose Intellisense which is a drag. Another option is to split the Front End and Back End and then deploy a Front End to each of your users, so they have their own FE database that they can destroy without affecting your other users. You may already know all about splitting the database, but just in case: http://bytes.com/topic/access/insigh...ront-back-ends
Sep 16 '15 #3
BikeToWork
124 100+
The code I put in the original post was a bad example. What I'm having trouble with is calling functions that use the worksheet object, to write text to a spreadsheet. For example the following code:
Expand|Select|Wrap|Line Numbers
  1. Sub ChoiceReport(ByRef RS As DAO.Recordset, strWKB As String, strCaption As String)
  2. 'Dim wks As Worksheet
  3.  
  4.  
  5. Dim lngRow As Long
  6. Dim rrow As Integer:      rrow = 3
  7. Dim actionFlag As String: actionFlag = ""
  8. Dim xlAPP As Object
  9. Dim WKB As Object
  10. Dim WKS As Object
  11.  
  12. Set xlAPP = CreateObject("Excel.Application")
  13. Set WKB = xlAPP.workbooks.Open(strWKB)
  14.  
  15.  
  16.  
  17.  
  18.  
  19.     Set WKS = WKB.Worksheets("ChoiceRpt")
  20.  
  21.  
  22.     writeCellText WKS, rrow - 2, 1, strCaption, actionFlag, "Center"
  23.  
This calls the "writeCellText" function:
Expand|Select|Wrap|Line Numbers
  1. Sub writeCellText(w As Object, ssRow As Integer, ssCol As Integer, someText, actionFlag As String, alignment As String)
  2.  
  3.     '   -------------------------------------------------------
  4.     '   Write the value into the cell - that's the easy part...
  5.     '   -------------------------------------------------------
  6.     w.Cells(ssRow, ssCol) = IIf(IsNull(someText), "", someText)
It does not write any text to the spreadsheet. I think the problem is that the "writeCellText" function doesn't know what the WKS object is that is passed to it as an object. How does one get around this? Do I need to send the string name of the WKS and then set it up with the xlApp application variable? Thanks for advice.
Sep 16 '15 #4
jforbes
1,107 Expert 1GB
This is working for me:
Expand|Select|Wrap|Line Numbers
  1. Sub ChoiceReport()
  2.  
  3.     Dim rrow As Integer: rrow = 3
  4.     Dim actionFlag As String: actionFlag = ""
  5.     Dim xlAPP As Object
  6.     Dim WKB As Object
  7.     Dim WKS As Object
  8.  
  9.     Set xlAPP = CreateObject("Excel.Application")
  10.     Set WKB = xlAPP.workbooks.Open("C:\Temp\Bytes\sampleTemp.xls")
  11.     Set WKS = WKB.Worksheets("ChoiceRpt")
  12.  
  13.     writeCellText WKS, rrow - 2, 1, "Test Text", actionFlag, "Center"
  14.  
  15.     WKB.Save
  16.     WKB.Close
  17. End Sub
  18.  
  19. Sub writeCellText(w As Object, ssRow As Integer, ssCol As Integer, someText, actionFlag As String, alignment As String)
  20.      w.Cells(ssRow, ssCol) = IIf(IsNull(someText), "", someText)
  21. End Sub
Are you getting an error? Also, you can get into that situation where the file is opened but not closed and then things start acting weird. Maybe close Access and attempt to rename the Excel File and try again.
Sep 16 '15 #5
BikeToWork
124 100+
JForbes, thanks for your help. That does work. Now that I am using late binding on this Access project, the spreadsheets seem to take extra long to generate. Is that to be expected?
Sep 16 '15 #6
jforbes
1,107 Expert 1GB
It will take longer. The calls themselves are supposed to take about twice as long to make and depending on how busy your application is, it could start adding up.

Here is a pretty good article on what you are doing: https://support.microsoft.com/en-us/kb/245115
Sep 17 '15 #7

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

Similar topics

16
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is evolving. This can be a problem when, ad example,...
2
by: j.b.messina | last post by:
This has not yet been published by Microsoft. It will be published within the next few weeks, mainly because I asked them to. I felt this was information badly needed, and I think this is the...
3
by: Shadow Lynx | last post by:
At the bottom of the default Error page that appears when Unhandled Exceptions occur, what exactly is the difference between the "Microsoft ..Net Framework Version" and the "ASP.NET Version"? I...
5
by: salad | last post by:
Is it preferable to create runtimes when distributing apps or preferable to expect the client to have valid versions of Office with Access on it. I have an app that requires Word and Outlook. So...
2
by: Hongbo | last post by:
Hi, I have a web site built in ASP.Net 1.1 running on production server. It's the version 1.0. Now I need to build the version 2.0 for this web site. The version 2.0 will be built based on the...
1
by: Sky | last post by:
Yesterday I was told that GetType(string) should not just be with a Type, but be Type, AssemblyName. Fair enough, get the reason. (Finally!). As long as it doesn't cause tech support problems...
0
by: ev951 | last post by:
I am not that familiar with XML or XSL and I am trying to sort application version number strings in an XML file that my team uses for application installations on our Linux servers. I have tried...
8
by: schaf | last post by:
Hi Ng! My application (version 1 a1) communicates with a service (version 1 s1). Now I would like to update the service and create a service version 2 (s2). The new function calls within s2 are...
4
by: Bob Altman | last post by:
Hi all, I have a C++/CLI project (VS 2005) that produces a DLL that exports C bindings. Internally, this DLL contains routines compiled with /clr. I notice that my DLL doesn't have a version...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.