I've been coding for some time using the following style:
Is it better to use the DAO style now?
ie:
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!!
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
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!!