Image Control in Sub-Routine Error

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.
 
B

Brendan Reynolds

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)
 
P

Peter Hibbs

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top