Image Control in Sub-Routine Error

  • Thread starter Thread starter Peter Hibbs
  • Start date Start date
P

Peter Hibbs

In Access 2003 -

I have a form with an Image control (the image is a .ICO icon type
file) called imgGreen. I am trying to set the BorderStyle property of
the control to Solid in a sub-routine by passing the control name to
the routine.

This is the basic sub-routine code :-

Public Sub IconBorders(vControl As Control)
vControl.BorderStyle = 1
End Sub

and I call the routine like this :-

IconBorders (imgGreen)

When the code is run it highlights the calling code above and gives
the error message -

Run Time error '438'
Object doesn't support this property or method.

Using the code :- imgGreen.BorderStyle = 1 works OK.

How can I change an Image control property in a sub-routine.

Peter Hibbs.
 
Peter Hibbs said:
In Access 2003 -

I have a form with an Image control (the image is a .ICO icon type
file) called imgGreen. I am trying to set the BorderStyle property of
the control to Solid in a sub-routine by passing the control name to
the routine.

This is the basic sub-routine code :-

Public Sub IconBorders(vControl As Control)
vControl.BorderStyle = 1
End Sub

and I call the routine like this :-

IconBorders (imgGreen)

When the code is run it highlights the calling code above and gives
the error message -

Run Time error '438'
Object doesn't support this property or method.

Using the code :- imgGreen.BorderStyle = 1 works OK.

How can I change an Image control property in a sub-routine.

Peter Hibbs.


I changed the code slightly to toggle border styles to make it easier for me
to test it ...

Public Sub IconBorders(vControl As Control)
If vControl.Properties("BorderStyle") = 1 Then
vControl.Properties("BorderStyle") = 2
Else
vControl.Properties("BorderStyle") = 1
End If
End Sub

The Control object doesn't have a BorderStyle property, but it does have a
Properties collection, and if the Control is an Image, then the Properties
collection with include a BorderStyle property. An alternative, if you don't
need to use the procedure with other types of control, would be to change
the declaration like so ...

Public Sub IconBorders(vControl As Image)

or perhaps better ...

Public Sub IconBorders(vImage As Image)
 
Brendan,

I actually tried the :-
Public Sub IconBorders(vControl As Image)

version before I posted and it gave the same error. However, your
other suggestion of using the .Properties method works perfectly.
Thanks very much for your help.

Peter Hibbs.
 
Back
Top