S
Scott
My function below gets the max date from a "Linked" table. It works fine
except if the file "c:\data\myBackend.mdb" doesn't exist. When that file
isn't there, I get the below error.
The error is on the "objRS.Open sSQL" line of code. Is there a way to add
error handling to this function to trap this error? I thought using the "If
Not objRS.EOF" would work, but unfortunately the error happens as soon as
the recordset is open.
ERROR *************
Could not find file c:\data\myBackend.mdb
CODE **************
Public Function GetMaxData()
Dim objRS As ADODB.Recordset, Conn As ADODB.Connection, sSQL As String
Set objRS = New ADODB.Recordset
objRS.ActiveConnection = CurrentProject.Connection
objRS.CursorType = adOpenForwardOnly
objRS.LockType = adLockReadOnly
Set Conn = CurrentProject.Connection
sSQL = "SELECT MAX(myDateField) FROM myTable"
objRS.Open sSQL, CurrentProject.Connection
If Not objRS.EOF Then
GetMaxData = objRS.Fields(0).Value
Else
GetMaxData = "n/a"
End If
objRS.close
Set objRS = Nothing
End Function
except if the file "c:\data\myBackend.mdb" doesn't exist. When that file
isn't there, I get the below error.
The error is on the "objRS.Open sSQL" line of code. Is there a way to add
error handling to this function to trap this error? I thought using the "If
Not objRS.EOF" would work, but unfortunately the error happens as soon as
the recordset is open.
ERROR *************
Could not find file c:\data\myBackend.mdb
CODE **************
Public Function GetMaxData()
Dim objRS As ADODB.Recordset, Conn As ADODB.Connection, sSQL As String
Set objRS = New ADODB.Recordset
objRS.ActiveConnection = CurrentProject.Connection
objRS.CursorType = adOpenForwardOnly
objRS.LockType = adLockReadOnly
Set Conn = CurrentProject.Connection
sSQL = "SELECT MAX(myDateField) FROM myTable"
objRS.Open sSQL, CurrentProject.Connection
If Not objRS.EOF Then
GetMaxData = objRS.Fields(0).Value
Else
GetMaxData = "n/a"
End If
objRS.close
Set objRS = Nothing
End Function