Re: Difference betten New & ...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Ralph (msnews.20.nt_consulting32_at_spamgourmet.com)
Date: 01/19/05


Date: Wed, 19 Jan 2005 06:52:24 -0600


"Jiju Joseph" <JijuJoseph@discussions.microsoft.com> wrote in message
news:1C595B68-F79F-4F36-B763-9D375EE045ED@microsoft.com...
> Hi,
>
> Can anyone tell me the difference between,
> 1. Dim a as New ADODB.Connection &
> 2. Dim a as ADODB.Connection.
>
> Tell me a difference other than memory allocation.

"Dim a As New ADODB.Connection"
Both declares and defines (creates) a Connection Object which is referenced
thru the Reference Variable 'a'.
It always insures that 'a' will reference a connection object, even
recreating one if necessary.
It has though the rest of your code is coded like this whenever you refer to
'a'.

      If IsNull(a) Then
           Set a = New ADODB.Connection
     End If
     Debug.Print a.Version

This adds additional often un-needed code.

If you manually set 'a' to Nothing, then you will automatically get a new
connection.
ie, Set a = Nothing ' becomes

      Set a = Nothing
      Set a = New ADODB.Connection

Which offers an interesting opportunity for failure.

Using... Dim a As ADODB.Connection
             ...
             Set a = New ADODB.Connection
             ...
             Set a = Nothing
Provides greater lattitude for control and less opportunity to shoot
yourself in the foot. (Well when it does happen you have an easier time
finding out where and how to repair. <g>)

hth
-ralph



Relevant Pages

  • Re: msofiledialogfilepicker error
    ... MyTitle As String, ByVal ftype As String, ByVal fdesc As String) ... As String Dim fDialog As Office.FileDialog ... That way you don't need a reference to the Office Object Library. ... The SET statement would work, returning an ADO connection object, ...
    (microsoft.public.access.modulesdaovba)
  • Re: msofiledialogfilepicker error
    ... MyTitle As String, ByVal ftype As String, ByVal fdesc As String) ... As String Dim fDialog As Office.FileDialog ... That way you don't need a reference to the Office Object Library. ... The SET statement would work, returning an ADO connection object, ...
    (microsoft.public.access.modulesdaovba)
  • RE: open arguments.
    ... The original to add a complete new quote, one to edit a quote and one to ... Dim rst As Recordset ... This opens the form specified by stDocName in data entry mode and passes the ... You want to store your reference so poke it into the reference field. ...
    (microsoft.public.access.modulesdaovba)
  • RE: open arguments.
    ... Dim rst As DAO.Recordset ... Just realised there is an Access object called Reference. ... This opens the form specified by stDocName in data entry mode and passes the ...
    (microsoft.public.access.modulesdaovba)
  • RE: open arguments.
    ... Dim dbs As DAO.Database ... Dim rst As DAO.Recordset ... Just realised there is an Access object called Reference. ... This opens the form specified by stDocName in data entry mode and passes the ...
    (microsoft.public.access.modulesdaovba)