June. I have a feeling you have not had much time with the Northwind database. RecordSetWrapper is a module. Let me paste it in for you
Code:
Option Compare DatabaseOption Explicit
Private m_rs As DAO.Recordset2
Public Function GetRecordsetClone(rs As DAO.Recordset2) As DAO.Recordset2
If Not m_rs Is Nothing Then
Debug.Assert False ' This is only designed to be used once
Else
Set m_rs = rs.Clone
Set GetRecordsetClone = m_rs
End If
End Function
Public Function OpenRecordset(Domain As String, _
Optional Criteria As String = "1=1", _
Optional OrderBy As String, _
Optional RecordsetType As DAO.RecordsetTypeEnum = dbOpenDynaset, _
Optional RecordsetOptions As DAO.RecordsetOptionEnum _
) As Boolean
If Not m_rs Is Nothing Then
' Close the recordset so it can be re-used
CloseRecordset
End If
Dim strSQL As String
strSQL = "SELECT * FROM [" & Domain & "] WHERE " & Criteria
If OrderBy <> "" Then
strSQL = strSQL & " ORDER BY " & OrderBy
End If
On Error GoTo ErrorHandler
Set m_rs = CurrentDb.OpenRecordset(strSQL, RecordsetType, RecordsetOptions)
OpenRecordset = True
Done:
Exit Function
ErrorHandler:
' verify the private Recordset object was not set
Debug.Assert m_rs Is Nothing
' Resume statement will be hit when debugging
If eh.LogError("RecordsetWrapper.OpenRecordset", "strSQL = " & Chr(34) & strSQL & Chr(34)) Then Resume
End Function
Public Function Delete() As Boolean
On Error GoTo ErrorHandler
m_rs.Delete
Delete = True
Done:
Exit Function
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("RecordsetWrapper.Delete") Then Resume
End Function
Public Function AddNew() As Boolean
On Error GoTo ErrorHandler
m_rs.AddNew
AddNew = True
Done:
Exit Function
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("RecordsetWrapper.AddNew") Then Resume
End Function
Public Function Edit() As Boolean
On Error GoTo ErrorHandler
m_rs.Edit
Edit = True
Done:
Exit Function
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("RecordsetWrapper.Edit") Then Resume
End Function
Public Function Update() As Boolean
On Error GoTo ErrorHandler
m_rs.Update
Update = True
Done:
Exit Function
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("RecordsetWrapper.Update") Then Resume
End Function
Public Function MoveNext() As Boolean
On Error GoTo ErrorHandler
m_rs.MoveNext
MoveNext = True
Done:
Exit Function
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("RecordsetWrapper.MoveNext") Then Resume
End Function
Public Function CloseRecordset() As Boolean
On Error GoTo ErrorHandler
m_rs.Close
CloseRecordset = True
Done:
Set m_rs = Nothing
Exit Function
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("RecordsetWrapper.CloseRecordset") Then Resume
End Function
Public Property Get Recordset() As DAO.Recordset2
Set Recordset = m_rs
End Property
Private Sub Class_Terminate()
If Not m_rs Is Nothing Then
m_rs.Close
Set m_rs = Nothing
End If
End Sub
and the code that used this function
Code:
Function Delete(OrderID As Long) As Boolean
Dim rsw As New RecordSetWrapper
If rsw.OpenRecordset("order details", "[Order ID] = " & OrderID) Then
With rsw.Recordset
If Not .EOF Then
Do While Not .EOF
Delete = rsw.Delete
.MoveNext
Loop
End If
End With
End If
If rsw.OpenRecordset("Inventory Transactions", "[Customer Order ID] = " & OrderID And "[transaction type]" <> 1) Then
With rsw.Recordset
If Not .EOF Then
Do While Not .EOF
Delete = rsw.Delete
.MoveNext
Loop
End If
End With
End If
Set rsw = Nothing
If rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
Delete = rsw.Delete
End If
End Function
Basically it works with single critera as in the 1st and 3rd ifs. But I can't seem to get it to work with the 2nd if with the multiple criteria
Also Please check my databse attached for the other issues i have posted. I have compacted and repaired it and made it under 2mb
Please let me know if there is anything I can do to make the database more efficient. Somehow it seems like im using hacks for what should be properly coded.
Appreciate your help.