Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What way is right?

Status
Not open for further replies.

combs

Programmer
Apr 18, 2002
78
US
I've been coding for some time using the following style:
Code:
Dim conn As Object
    Dim rs As Object
    Dim strSql As String
    Set conn = Application.CurrentProject.Connection
    Set rs = CreateObject("ADODB.Recordset")
    strSql = "SELECT Project, ProjectDescription FROM tblGlobalVars;"
    rs.Open strSql, conn, 1
    If Not rs.EOF Then
        'PROJECT NAME
        If IsNull(rs("Project")) = False Then
            lblDatabase.Caption = rs("Project")
        Else
            lblDatabase.Caption = "CGS " & Year(Date)
        End If
    End If
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing
Is it better to use the DAO style now?
ie:
Code:
    Dim conn DAO.Database
    Dim rs As DAO.Recordset
    Dim strSql As String
    Set conn = CurrentDb()
    strSql = "SELECT Project, ProjectDescription FROM tblGlobalVars;"
    rs.Open strSql, conn, 1
    If Not rs.EOF Then
        'PROJECT NAME
        If IsNull(rs("Project")) = False Then
            lblDatabase.Caption = rs("Project")
        Else
            lblDatabase.Caption = "CGS " & Year(Date)
        End If
    End If
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing

I imagine that my example of the DAO style is not quite correct... Could someone take the time to explain which style is better and maybe point out some good references??

What brings this question on is that all of the sudden I am getting lots of "Module not found" and "Object variable or with block variable not set" errors that are popping up and rendering my database useless. The errors usually happen when the switchboard is initializing and nothing can be done (i.e. since the switchboard cannot be opened, the rest of the database cannot be used) If I try to bypass the switchboard and open up another form, the same error appears!!

Help Please!!
 
These are not styles of coding, but methods used by your database to access data. DAO goes straight through the Jet engine, whereas ADO goes straight to the required datalayer. So I suppose if you are only using Access datalayer, there may be slight advantages to using DAO. I work primarily with SQL Server back ends, so I have never actually used DAO.

But I think that this link might help you get started.
Good Luck,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top