Setting up Collections

Roly Reefer

Registered User.
Local time
Today, 17:00
Joined
Jan 28, 2005
Messages
37
I am teaching myself Access VBA and have got a problem with setting up a new collection, which I can't resolve in help or google.

I have been shown this code for setting up a collection, which is basically to set txtcustomers on form 0 (frmcustomers) as item 5. I didn't get the first line of code and tried it in a Public sub first, but I keep getting an error saying Compile Error: Invalid use of property.

Public Property Set Collecion(p As Control)

Forms(0).Controls (5)
Forms("frmCustomers").Controls ("txtCustomerID")
[Forms!frmCustomers!txtCustomerID]

End Property


Please can someone give me the missing bits of code.

Thanks very much.
 
Those three lines of code are syntactically different but functionally equivalent examples of how to reference a control on an open form. In respect to collections, those don't 'set one up' but they do demonstrate examples of how to reference objects that are members of collections.
The 'Application' object exposes 'Forms', a collection of open forms.
The 'Form' object exposes 'Controls', a collection of controls on the form.
You get a compile error because you don't use the reference. Try code like ...
Code:
Sub Test
  debug.print forms(0).controls(5).name
End Sub
In that code you reference the control, consume it's name property and print the result. That will compile just fine.
 

Users who are viewing this thread

Back
Top Bottom