Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2002
    Posts
    44

    Unanswered: set dbCur = CurrentDb ????

    I have seen in a lot of example code with recordsets and such where the programmer first creates a database object, then sets that object to the CurrentDb object, and then uses the new database object to open recordsets.

    My question is, why go to the trouble of making a new database object.

    eg.

    Dim dbCurr as Database
    Dim rs as Recordset

    Set dbCurr = CurrentDb
    Set rs = dbCurr.OpenRecordset("tblMyTable")


    why do that instead of:

    Dim rs as Recordset

    Set rs = CurrentDb.OpenRecordset("tblMyTable")




    Just wondering if I have been missing something.

    Thanks.

  2. #2
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    I will agree with you for a local database. But, if you are using multiple databases at different locations, you will need to set the location for your databases. Some programmers just stick to one method and use it regardless of database location.

    An example:

    Dim dbPath as String
    Dim db as Database
    dbPath = "C:\Folder\Database.mdb"
    Set db = DBEngine.Workspaces(0).OpenDatabase(dbPath)

    Does this make sense?

    Kal

  3. #3
    Join Date
    Nov 2001
    Posts
    336
    Hi,

    I would assume that using object variable db instead of function call CurrentDB() may improve perfomance, provided that you refer to db several times in your code.

    Igor

  4. #4
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Exactly,

    Especially for updating data definition. Continuing.....

    db.Execute (Some SQL Statement)
    db.TableDefs!SomeTable
    etc...

  5. #5
    Join Date
    Nov 2001
    Posts
    336
    another example:

    db.OpenRecordset(...)

  6. #6
    Join Date
    Apr 2002
    Posts
    44
    so what you are saying, is that if I am only using 1 database, then I should probably create a global variable at the beginning of my project and set it to CurrentDb and then reference that database object whenever I need to open a recordset. I don't see any "cost savings" if for each subroutine you re-define a database object and set it to CurrentDb, because doing it that way you will still be making a lot of calls to CurrentDb.

  7. #7
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Hey Bob,

    I wouldn't bother. I was just trying to explain that some programmers (like me) prefer to set the Workspace regardless of database location. I understand that it is not necessary.

    Kal

  8. #8
    Join Date
    Nov 2001
    Posts
    336
    Hi,

    I sometimes create dbase variable:

    set dbase=currentdb()

    and use it in the application. The main reason is that it's easier to type dbase than currentdb().

    Igor

  9. #9
    Join Date
    Apr 2002
    Posts
    44
    cool...thanks for the inputs guys...I'm wrapping up my first "major" multi-user Access app, just trying to tweak out all the little things as much as possible now..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •