stickleprojects Level: Moderator

 Registered: 09-09-2002 Posts: 901
|
Re: Getting Compile Error using Database Object in VBA
Hi BlackDuck
It looks like you are making impressive headway here (wish more people attempted stuff in this manner - it's only a few of you guys that actual try!)
So...
First off. In visual basic (and all variants of it - VBA/VB6/VBNET/7), there is a difference between an Object and a simple data type. All objects MUST have the word SET in front of them when using a variable:
E.G.
Set MyDb - currentdb()
Set MyObject = thatobject
You can tell the difference by the variable type. IF it's not String, Integer, Date, Double or Single - it's probably an Object and should have the keyword "SET"
There is no real reason for this apart from MS deciding that it would be a good idea.
In Microsoft Active DAta Objects and in Data Access Objects (ADO and DAO to you and me), Microsoft declared a "thingy" called a recordset. As you already worked out, one of the issues you had was because access didn't know which particular thingy you wanted (Recordset, Database, etc.) - by telling Access which one you wanted (ie. Dim rs as ADO.Recordset, or Dim rs as DAO.Recordset) you got around this issue.
IMPORTANT!!!
IF YOU IGNORE ANYTHING ELSE I'VE WRITTEN, DON'T IGNORE THIS BIT!!!!
By putting Brackets around something, you are asking vb (or VBA) to "take a quick estimate as to what it is"... really really really a bad idea. NEVER put brackets round something unless it is a calculation (ie. a function call, or a multiple or adding some strings together or numbers or something)! VB also copies the values rather than passing them by reference (brackets mean use resultant not source).
Just my tuppence worth
Well done BlackDuck - keep up the good work 
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
|