Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ! vs . (can anyone tell me the difference?) (any version)

    Can anyone point me to anything on the difference between using ! and . to refer to forms, subforms, and controls?

    I've been doing this access stuff for a while now, and I've always ignored that there is a difference. But I was asked to work on someone else's database (ick) and noticed that the person's use of ! and . was completely different from mine. I've always used ! to refer to forms and . to refer to controls (and properties). This person uses ! to refer to everything, controls included, and it seems to work just fine.

    Does it make a difference?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ! vs . (can anyone tell me the difference?) (any version)

    The bang ! is used to refer to a member of a collection, and the dot . to refer to a property.

    However, in many situations members of a collection also count as properties, so you can use both ! and . to refer to a member of a collection.

    For example, you can refer to an open form frmCustomers as Forms!frmCustomers and as Forms.frmCustomers. And also as Forms("frmCustomers"), for that matter.

    To refer to the text box txtLastName on frmCustomers, you can use Forms!frmCustomers.Controls!txtLastName. Controls is a property of the form, Controls itself is not a member of a collection, so Forms!frmCustomers!Controls!txtLastName will cause an error. But Controls is the default property of a form, so you can omit it: Forms!frmCustomers!txtLastName. Forms!frmCustomers.txtLastName and Forms.frmCustomers.txtLastName and Forms!frmCustomers.txtLastNameare also valid.

    Caption is just a property of the form, so Forms!frmCustomers.Caption is correct, but Forms!frmCustomers!Caption will cause an error.

    As you see, ! and . can be used interchangeably in many situations, but not always.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ! vs . (can anyone tell me the difference?) (any version)

    Additional reasons to use dot

    <pre>Private Sub LastName_AfterUpdate()
    Dim strLastName As String
    strLastName = Me.la (this will popup intellisense window so you can choose LastName)
    End Sub


    ‘This will generate an error on compile
    Private Sub LastName_AfterUpdate()
    Dim strLastName As String
    strLastName = Me.LastNamex
    End Sub


    ‘This will not generate an error on compile, but will error when run
    Private Sub LastName_AfterUpdate()
    Dim strLastName As String
    strLastName = Me!LastNamex

    End Sub
    </pre>


  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ! vs . (can anyone tell me the difference?) (any version)

    Thanks to both of you! Yeah, I guess I tend to use . because of the intellisense thing. Since it seems to make no (overall) difference, I'll stick with the .

Posting Permissions

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