Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 911
  • Last Modified:

recordsets, late binding and currentDB

I want to know if there is a difference between these different methods of working with a recordset
1)

dim db as database  '(assume I set a reference to DAO)
dim rst as recordset
set db = currentDB
set rst = db.openrecordset("sql")

VS
2)

dim rst as recordset '(still have a reference to DAO but left out the db database object)
set rst = currentDB.openrecordset("whatever")

VS
3)

dim rst    '(no reference set... how does access handle late binding in this instance? does it use ADO, DAO, or some other library?)
set rst = currentDB.openrecordset("whaterver")

I  have only been on EE for a week and do not have many points to award... but this should be an easy question for someone who knows...
0
mydatabaseguy
Asked:
mydatabaseguy
  • 5
  • 3
  • 2
2 Solutions
 
harfangCommented:
1) CurrentDB is executed once (a fresh instance of a database object is created).
Advantage, you can reuse the same "db" for other things.

2) Same as above, except that the fresh instance is not stored. It is destroyed after executing the line

3) Still the same. CurrentDB is DAO, so the recordset is also. Only differenct is later:
   rst.FindFirst ...

In case 3, the FindFirst method is bound at run time, while in the other cases it is bound at compile time.

Hope this helps, don't hesitate to expand on the question...

Cheers!
0
 
mydatabaseguyAuthor Commented:
Hey thanks for the quick reply... Everything makes sense except for 'CurrentDB is DAO'.

I am a little confused since currentDB is a function that is always available, even without a reference to DAO.
0
 
flavoCommented:
You are right mydatabaseguy

The currentdb function is a "built in" to access and not the DAO Obj. Lib (Look at the object browser), however if you wish to set it to a variable (ie set db = currentdb) then you MUST have the DAO dll installed on the pc, this is becasue the object that the currentdb function returns is a member of the DAO object (a databse object)

I hope this clears it up a little for you.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
mydatabaseguyAuthor Commented:
Thanks guys for your responses! I wish I had more points to give, but again I have only been on for a week (I answered questions to get my points)

Thanks again!
0
 
flavoCommented:
3400 more an you'll get unlimited.

10,000 points and 3000 or more in a month and you get Premium Services.

Thanks mate, good luck!

Dave
0
 
harfangCommented:
Dave,
Just a slight correction. You CAN use "Set db = CurrentDb" without the library. The library is used only for early binding at compile time. So it's "Dim db As DAO.Database" with will fail. You can always use "Set db As Object"...
Not much difference, but as this IS the topic of the question, I felt I had to...
Cheers!
0
 
harfangCommented:
While I'm here, learn the power of TypeName()... In the Immediate Pane (aka Debug Window):
   ? TypeName(CurrentDb)
   Database
   set DummyVar = CurrentDb.OpenRecordset("tblAnyTable")
   ? TypeName(DummyVar)
   Recordset
   set DummyVar = Nothing

Cheers!
0
 
flavoCommented:
Yes,

try deleting your dao351.dll and dao360.dll and tell me how good it goes. (>> then you MUST have the DAO dll installed on the pc)

I know the difference between late and early binding mate, i never said anything about refrences

 ? TypeName(CurrentDb)
   Database

which is a member of DAO

0
 
harfangCommented:
Sorry, Dave, just a misunderstanding. Of course the dll is needed, I meant only the *reference* to the dll. So saying "you don't need the library" was incorrect.
0
 
harfangCommented:
(and of course, the pointer to TypeName() was not meant for you :)
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now