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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » ! vs . (can anyone tell me the difference?) (any version)

    Author
    Topic
    #454857

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #1130196

      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.

      • #1130231

        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 .

    • #1130227

      Additional reasons to use dot

      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
      
    Viewing 1 reply thread
    Reply To: ! vs . (can anyone tell me the difference?) (any version)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: