[AccessD] Elegant Solution?

Gustav Brock gustav at cactus.dk
Fri Sep 24 05:14:50 CDT 2004


Hi Vlad

I use copy-and-paste ...

In 2000 I brought up the idea of "terminating" any object before
exiting a function. Shamil suggested this solution:

<quote>

I think you can write the following sub which slightly extends
Gustav's idea: 

Sub TerminateExt(ParamArray aobj() As Variant)
  On Error GoTo TerminateExt_Err
  Dim lngIdx As Long

  If UBound(aobj) > -1 Then
    For lngIdx = 0 To UBound(aobj)
      aobj(lngIdx).Close
      Set aobj(lngIdx) = Nothing
    Next lngIdx
  End If

TerminateExt_Exit:
  Exit Sub

TerminateExt_Err:
  Select Case Err
    Case 91
      ' Object obj doesn't exist.
    Case 438
      ' Object obj doesn't support method close.
    Case 3420
      ' Object obj has already been closed.
    Case Else
      ' Unknown error.
      MsgBox "Error " & Err & ". " & Err.Description, _
        vbExclamation, _
        "Error terminating object (ParamarrayIndex = " & lngIdx & ", "
& _
        "TypeName = " & TypeName(aobj(lngIdx)) & ")"
  End Select
  Resume Next
End Sub

and use it in your case this way:

  TerminateExt MyObject2, MyObject1, rst,db

HTHAWOK,
Shamil

---

But I must admit I've never used it ...

/gustav


> Does anyone have any code or such that handles the following elegantly:
 
> Dim dbs as DAO.Database
> Dim rst as DAO.Recordset
 
> Set dbs etc etc
 
> Do whatever here
 
> dbs.close
> dbs = nothing etc etc
 
> I am tired of having do the above to open database connections and
> recordsets in the above manner in every Sub or Function. Surely there's
> a  more elegant method that someone has come up with here you just parse
> the SQL Statement through or something...
 
> Any suggestions or links will be greatly appreciated...
 
> Regards
> Vlad




More information about the AccessD mailing list