Can anyone tell me what the difference is between these two codes?
Code1
Code2Code:Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Code:Dim rs
Set rs = CreateObject(blah) 'not too sure how to use this function
Printable View
Can anyone tell me what the difference is between these two codes?
Code1
Code2Code:Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Code:Dim rs
Set rs = CreateObject(blah) 'not too sure how to use this function
With the first one, you already have a reference in place.
You add in the reference from the properties menu in vb. Setting a reference here, lets you type in the code as in your first example. :)
The second one is you creating and setting up the reference to the object via code. This is useful as with vbscript for example - when you're using notepad, you don't have a nice project menu to do all this for you.
With the createobject method, as you create the reference, there's no need for the New keyword as it's automatically a new reference of the object.
So -
Project > Properties > microsoft Excel 8.0 object
is just getting microsoft to do the following for you -
set ObjXls = createobject("Excel.Application")
Hope I made some sense there ! :rolleyes:
Ahh, I get it now, thanks alex! :)
Also, setting a reference (early-binding) is much faster than using CreateObject at runtime(late-binding).
Yeah, I had a feeling that came in to it. Thanks also. :)