Hi All,
I am new to this forum and I have registered to research a very specific issue.
First of all, I would like to mention that I am not an Access-VBA Developer. It just happens that at work place we have a legacy Access system that we still need to support. I am reading into access-vba, but not competent enough to tackle this particular problem, so I am here to ask for your help.
I have found snippets on the Internet for the "Late Binding" Solution to different Office-Excel Versions on users PCs.
I have managed to get excel object referencing to work with "late binding" . My scenario is as follows
1. user logs in
2. user is transferred to a "switchboard" form-menu.
3. in the OnLoad event of the switchboard form I check for any existing excel references and remove them (I have found that if i dont, it was not working properly)
Code:
If refExists("excel") Then
Access.References.Remove Access.References("excel")
End If
which uses the following
Code:
Private Function refExists(naam As String)Dim ref As Reference
refExists = False
For Each ref In References
If ref.Name = naam Then
refExists = True
End If
Next
End Function
4. It then checks for office installations using the following code (i only declare it once here, but it covers all possibilities for office 2007,2010,2013,2016 , both 32 or 64 bit and 32 or 64 bit Windows OS)
Code:
If Dir("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe") <> "" Then Access.References.AddFromFile ("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe")
End If
5. I then disable the X Close button of Access Main Application window, so that I force users to click on a "close" button on the switchboard form which in turn again checks for any excel references and removes it.
It all work fine, and we have tested the same excel file on excel 2010, 2013 and 2016 and works as expected.
At least that is what we thought.
the problem is that some other functionality has been lost, and I have managed to pinpoint the piece of code which "causes" the problem.
it seems that when a path for office installation and excel.exe is found (in my case the following)
Code:
If Dir("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe") <> "" Then Access.References.AddFromFile ("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe")
End If
it somehow "destroys" the values of some public parameters, that hold the user role.
some buttons on another form are hidden or shown according to some roles, and as the public parameter holding the role value is NULL then the buttons are not shown as expected.
If i just leave all code untouched and just comment out the above line of code where it adds a reference, it all works as expected.
I have traced (with msgbox messages) the values for the public parameter, and it exists, right before the Access.References.AddFromFile ("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe") line and right after it its NULL.
i have also created a temp parameter, assigned it the value of the public parameter before it gets NULLed and reassign it back to the public parameter after the add reference code, BUT ITS STILL NULL !!!!
one more thing to mention, is that the public parameter i am talking about that holds the role name, is placed in a MODULE if that makes a difference.
As I said, my background is not Access-VBA so you have to be lineant with me !
Thank you in advance and I hope I get some info on this matter,
George