Albert D. Kallal
Active member
- Local time
- Yesterday, 19:17
- Joined
- Jun 11, 2009
- Messages
- 106
Yes, 100% correct in terms of hard coding such values.I have used zip files that includes runtimes for installs, but only if the target has no Access installed.
Well, I do have some interop apps that have constants, so do you suggest hardcoding magic values as a workaround?
And a simple example?
While I used the Office "FileDialog"?
It does require the Office 16 library?
You can over the years have used late binding, and thus that file dialog code would become:
Code:
' Original posted code:
Dim f As FileDialog
Set f = Application.FileDialog(msoFileDialogFilePicker)
f.Show
MsgBox "file choose was " & f.SelectedItems(1)
'You can late bind if you wish:
'If you remove the reference to the 16.0 object library, then the following
' code will work without any references:
Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
f.Show
MsgBox "file choosen = " & f.SelectedItems.Count
So, yes, those constants (like msoFileDialogFilePicker in this example), do require changes.
As noted, you can during development do a "regasm", and use early binding.
In fact Visual Studio has a option to do a regasm for you during the build.
(thus, this feature/option ONLY applies to your dev computer - it does NOT change the .dll one bit).
That option is this one in VS:
So, if you tick above, then .net will do a regasm for you. This VERY much suggests then that you MUST force the project to x86, or x64, and ANY CPU will not work. But, if you do check the above box, and build? Then you launch Access, and under VBA->tools->references?
You will indeed find the COM object.
So, the above can be handy during development, but that Register option as noted, is ONLY for development - it does not change the project or .dll in anyway.
So, often during development, we often do use early binding. And I suppose the REALLY cool question?
Is how to debug the .net code when it called from VBA? (and again this is really easy, and really cool).
If you wish, do ask, and I'll post how to do this trick - but, probably in the next day or so....
R
Albert