[RESOLVED] VB6 binding access object library or ..?
hi I'm new this is my first post and i need your help.
Ive made a program and i use a reference to Microsoft access 10.0 object library, it works fine on my comp but not on others.
i only need this reference because its the only way i know how to turn a string into a formula using; formula = Eval(string).
do i have to bind the reference or something? if so, how?
or can you give me a different way to turn a string into a formula?
thanks, tag
Re: VB6 binding access object library or ..?
Welcome to VBForums :wave:
In order for a Reference to a Microsoft Office application (including Access/Word/Excel/etc) to work, that application has to be installed on the computer that the code is running on. If you use a Reference it generally also needs to be the same version as you programmed against (this limitation can be removed by using Late Binding rather than a Reference).
I'm fairly sure that the Scripting Runtime (which is included with Windows) has the feature you are looking for, but unfortunately I don't know the code for it - a search of this site should find it tho.
Re: VB6 binding access object library or ..?
well thanks, if it will work on any comp with access and not just 10.0 then thats a bit better,
but ive never done any late binding before so detailed help would be much appreciated .
ive been seaching the forums and cant find any code for this without using a reference.
ps: f1 rules
Re: VB6 binding access object library or ..?
Late binding = you declare the object as a generic Object instead adding a reference and then use the specific object type.
Ie. instead of adding reference to Access 10.0 and declaring Dim YourObject As Access100.TheAccessObject (pseudocode as I don't know the exact ones) you use Dim YourObject As Object and then call Set YourObject = CreateObject("TheAccessObject", "Access100") – you can use Object Browser (press F2) to find out the correct strings. Searching for CreateObject may also be of help.
The downside of late binding is that 1) it is slower and 2) you do not get intellisense, you have to write code without any help by IDE as you type.
Re: VB6 binding access object library or ..?
all a bit confusing,
"instead of adding reference to Access 10.0 and declaring Dim YourObject As Access100."
instead of? but i didnt need to declare anything before.
right ive declared an object now, and put the set object on the command in use,
but i dont know what to put in the any of the brackets.
Set YourObject = CreateObject(Class As String, [ServerName As String])
ive never used objects before
thanks
Re: VB6 binding access object library or ..?
Quote:
Originally Posted by
tag666
instead of? but i didnt need to declare anything before.
You should have, but MS Office applications are a bit odd in that way... and your program has bugs unless you are careful (such as leaving the Office application open but hidden after your program exits).
Quote:
but i dont know what to put in the any of the brackets.
Set YourObject = CreateObject(Class As String, [ServerName As String])
Based on what works for Excel, I would guess at this:
Code:
Dim YourObject As Object
Set YourObject = CreateObject("Access.Application")
formula = YourObject.Eval(string)
YourObject.Quit 'this may fail, but you need something like it (perhaps .Close ?)
Set YourObject = Nothing
Quote:
ive never used objects before
Actually you have, you just haven't realised it.
Most things you can see in your program (such as forms and textboxes etc) are objects, but they do the Set (and close) work for you automatically.
Re: VB6 binding access object library or ..?
thanks again. youve both been great help!
what i finally found to work in the brackets is as follows:
Set YourObject = CreateObject("MSScriptControl.ScriptControl")
YourObject.Language = "VBScript"
but YourObject.Close, YourObject.Quit and unload(YourObject) all dont work
Re: [RESOLVED] VB6 binding access object library or ..?
Using the ScriptControl is a better option, because it does not rely on the user(s) having MS Access installed (only something that is included with Windows, and thus they will have it already), and it is likely to be quicker too.
The .Quit/etc are for use with Office programs, and you probably don't need that for the ScriptControl.