Results 1 to 4 of 4

Thread: General

  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    General

    In the book "Access 2000 Developer's Handbook Vol 1: Desktop Edition", pages 221 & 222, it states the following:
    "When you create an object variable, Access creates only a 'pointer'. That is, the variable it creates refers to a real object; it's not a real object itself. It contains not the value of the object, but its memory address instead."

    It then gives a number of examples:
    Dim cnn as ADODB.Connection
    Dim rst as ADODB.Recordset
    Dim frm as Form
    Dim ctl as Control
    etc.

    My question is:
    If the variable is strictly a pointer (space for memory address) and since (I am assuming) the memory address is always the same size, why don't we just code as follows:
    Dim cnn as Object
    Dim rst as Object
    Dim frm as Object
    Dim ctl as Object
    etc?

    I can understand the need for specific Set statements:
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    Set frm = Forms("frmCustomers")
    Set ctl = frm.Controls("txtCompanyName")

    I can see the need to assign specific addresses. I can't see the need to be specific when setting aside the neccessary space for an (any) address.

    I am sure there are some who understand the nuts and bolts of this.
    Just curious.[img]/w3timages/icons/baby.gif[/img]

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Edmonton, Alberta, Canada
    Posts
    326
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General

    You can. However, if you declare your variable as something specific (e.g. form, control, or whatever) and then type the variable followed by a period, Access is nice enough to show you what properties or methods can follow the period in that context. Also, if you goof and use a property or method that doesn't apply to whatever you're working with, you'll get a compile error rather than a run-time error, and it's a lot easier to find compile errors! [img]/w3timages/icons/smile.gif[/img]

    Declaring things as "object" means you don't get those features.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: General

    AHA...Thank You Mr. Martin! [img]/w3timages/icons/clever.gif[/img].
    I think that's worthwhile information to have.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: General

    It isn't only that those features don't show up in intellisense, they aren't available, period unless you assign the right type of object to that variable.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •