By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,391 Members | 1,926 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,391 IT Pros & Developers. It's quick & easy.

unknown property works

100+
P: 553
I have got this piece of code:

Expand|Select|Wrap|Line Numbers
  1. Dim Ctrl As Control
  2.  If Ctrl.ControlType = acCheckBox Then
  3.  
my question is when i try to reference Ctrl, i dont get an property box poped up - seems like Ctrl of Control type hasn't got any property called .ControlType - but the above code still works and i get no error !

is that property hidden somewhere.. are there any hidden properties at all?
Aug 8 '07 #1
Share this Question
Share on Google+
6 Replies


dima69
Expert 100+
P: 181
I have got this piece of code:

Expand|Select|Wrap|Line Numbers
  1. Dim Ctrl As Control
  2.  If Ctrl.ControlType = acCheckBox Then
  3.  
my question is when i try to reference Ctrl, i dont get an property box poped up - seems like Ctrl of Control type hasn't got any property called .ControlType - but the above code still works and i get no error !

is that property hidden somewhere.. are there any hidden properties at all?
Well, not all properties are popped up in vb editor (not just the hidden ones).
To see hidden properties, go to Object Browser and check the "Show Hidden Members" option from the right click popup menu.
Aug 8 '07 #2

ADezii
Expert 5K+
P: 8,669
I have got this piece of code:

Expand|Select|Wrap|Line Numbers
  1. Dim Ctrl As Control
  2.  If Ctrl.ControlType = acCheckBox Then
  3.  
my question is when i try to reference Ctrl, i dont get an property box poped up - seems like Ctrl of Control type hasn't got any property called .ControlType - but the above code still works and i get no error !

is that property hidden somewhere.. are there any hidden properties at all?
You have declared an Object Variable As Type Control, but you have not explicitly assigned it to an Object. Take a look at the following 2 code segments which work as they should.
  1. Loop through all the Controls on a Form and if the Control is a Check Box, print out its Name:
    Expand|Select|Wrap|Line Numbers
    1. Dim Ctrl As Control
    2.  
    3. For Each Ctrl In Me.Controls
    4.   If Ctrl.ControlType = acCheckBox Then
    5.     Debug.Print Ctrl.Name
    6.   End If
    7. Next
  2. Assign the Object Variable Ctrl to a Text Box named txtLastName and set its Background Color to a Random Number between 0 and 15 (possible values of QBColor() Function):
    Expand|Select|Wrap|Line Numbers
    1. Dim Ctrl As Control
    2. Randomize
    3. Set Ctrl = Me![txtLastName]
    4. Ctrl.BackColor = QBColor(Int(Rnd * 16))
  3. Let me know how you make out.
Aug 8 '07 #3

100+
P: 553
ADezii

Thanks for the code.

but again, even this code:
Ctrl.BackColor <- - BackColor is not a property of Ctrl, howcome its working.

I dont understand very well what you mean by 'i have declared an Object Variable As Type Control but you have not explicitly assigned it to an Object' ...

Ctrl is itself an object, why would i assign it to any other object?

Thanks

You have declared an Object Variable As Type Control, but you have not explicitly assigned it to an Object. Take a look at the following 2 code segments which work as they should.
  1. Loop through all the Controls on a Form and if the Control is a Check Box, print out its Name:
    Expand|Select|Wrap|Line Numbers
    1. Dim Ctrl As Control
    2.  
    3. For Each Ctrl In Me.Controls
    4.   If Ctrl.ControlType = acCheckBox Then
    5.     Debug.Print Ctrl.Name
    6.   End If
    7. Next
  2. Assign the Object Variable Ctrl to a Text Box named txtLastName and set its Background Color to a Random Number between 0 and 15 (possible values of QBColor() Function):
    Expand|Select|Wrap|Line Numbers
    1. Dim Ctrl As Control
    2. Randomize
    3. Set Ctrl = Me![txtLastName]
    4. Ctrl.BackColor = QBColor(Int(Rnd * 16))
  3. Let me know how you make out.
Aug 9 '07 #4

ADezii
Expert 5K+
P: 8,669
ADezii

Thanks for the code.

but again, even this code:
Ctrl.BackColor <- - BackColor is not a property of Ctrl, howcome its working.

I dont understand very well what you mean by 'i have declared an Object Variable As Type Control but you have not explicitly assigned it to an Object' ...

Ctrl is itself an object, why would i assign it to any other object?

Thanks
  1. As you have displayed Ctrl, it is not an Object but a Object Variable pointing to an Object. The same concept as:
    Expand|Select|Wrap|Line Numbers
    1. Dim intCounter As Integer
    intCounter is not an Integer, it is just a Variable assigned as Type Integer and as of now does not equal anything.
  2. Once you assign Ctrl (Instantiate) to a specific Object, it not points to that Object as in:
    Expand|Select|Wrap|Line Numbers
    1. Dim Ctrl As Control
    2. Set Ctrl = Me![txtLastName]     'points to Me![txtLastName]
  3. BackColor is a Property of Ctrl but your are just accessing it the wrong way and it has to do with the specific Property Type, for instance:
    Expand|Select|Wrap|Line Numbers
    1. Ctrl.Properties("BackColor") = vbRed        'works fine
  4. Some Properties can be accessed by using the Dot (.) Syntax (Built-in) while others must be accessed via the Properties Collection for the specific Object.
  5. It is, in fact, very confusing.
Aug 9 '07 #5

100+
P: 553
Hey ADezii

Thank you very much !

  1. As you have displayed Ctrl, it is not an Object but a Object Variable pointing to an Object. The same concept as:
    Expand|Select|Wrap|Line Numbers
    1. Dim intCounter As Integer
    intCounter is not an Integer, it is just a Variable assigned as Type Integer and as of now does not equal anything.
  2. Once you assign Ctrl (Instantiate) to a specific Object, it not points to that Object as in:
    Expand|Select|Wrap|Line Numbers
    1. Dim Ctrl As Control
    2. Set Ctrl = Me![txtLastName]     'points to Me![txtLastName]
  3. BackColor is a Property of Ctrl but your are just accessing it the wrong way and it has to do with the specific Property Type, for instance:
    Expand|Select|Wrap|Line Numbers
    1. Ctrl.Properties("BackColor") = vbRed        'works fine
  4. Some Properties can be accessed by using the Dot (.) Syntax (Built-in) while others must be accessed via the Properties Collection for the specific Object.
  5. It is, in fact, very confusing.
Aug 10 '07 #6

ADezii
Expert 5K+
P: 8,669
Hey ADezii

Thank you very much !
You are quite welcome.
Aug 10 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.