Search code examples
ms-accesspropertiescontrolscustomization

MSACCESS - How to create a custom property for a control


There is a way to create a public custom property for a control, a textbox for instance? I just want to add a border color to a textbox like this:

public property Empty(ValX as Boolean)

if ValX = true then
 Screen.ActiveControl.BorderWidth = 10
 Screen.ActiveControl.BorderColor = RGB(255, 0, 0)
else
 Screen.ActiveControl.BorderWidth = 0
 Screen.ActiveControl.BorderColor = RGB(0, 0, 0)
end if

end property

so i can use it like this:

text1.Empty=true

This is just an example of what i need.. Thanks in advance


Solution

  • You can' overload or create your own control by inheriting from a base control.

    The best you can get/do?

    This would work:

    Public Sub MyEmpty(c As Control, Highlight As Boolean)
    
      If Highlight Then
         c.BorderWidth = 6
         c.BorderColor = RGB(255, 0, 0)
      Else
         c.BorderWith = 1
         c.BorderColor = RGB(0, 0, 0)
      End If
    
    End Sub
    

    Thus , in form code? You would go like this:

    MyEmpty Text1, True
    

    As a FYI? the border width is 0 to 6 allowed values. But the color as above should work just fine.

    So, not a lot of code, and not a lot of typing - but a wee bit more then if you could have created a custom property of a control - but it not a option. Above should work ok, and you don't have to rely on screen.active as a result.