Convert string to object

M

Mat Child

Hi,

Currently i have some subs that perform common tasks on many forms within
the DB.
When calling the sub the form's object description is passed through

eg
the following colours in the form based on a value displayed on it.

Public Sub ColourMeIn(callingform As Object, Reason As String)

Dim Colour As Long
Select Case (Reason)
Case "LANDESK"
Colour = 6723891
Case "DEPLOYMENT"
Colour = 16035722
Case "STACK"
Colour = 39423
Case "VANILLA"
Colour = 14548479
End Select

With callingform
.FormHeader.BackColor = Colour
.Detail.BackColor = Colour
.FormFooter.BackColor = Colour
End With

End Sub


it's normally called as follows

ColourMeIn Forms![1-05 VIEW RELEASE].Form, Me!Rel_Type

Instead of explicitly coding the name of the form i'm trying to use a method
of calculating the value. I can create a string that replicates the name

formname = "forms![" & me.Name & "].form"
but passing this value to the sub causes the error "ByRef argument type
mismatch"

is there anyway to convert the string to an object?
 
M

Mat Child

Thanks Ken

That does just what i wanted

Mat

Ken Snell said:
formname = forms(me.Name).form

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



Mat Child said:
Hi,

Currently i have some subs that perform common tasks on many forms within
the DB.
When calling the sub the form's object description is passed through

eg
the following colours in the form based on a value displayed on it.

Public Sub ColourMeIn(callingform As Object, Reason As String)

Dim Colour As Long
Select Case (Reason)
Case "LANDESK"
Colour = 6723891
Case "DEPLOYMENT"
Colour = 16035722
Case "STACK"
Colour = 39423
Case "VANILLA"
Colour = 14548479
End Select

With callingform
.FormHeader.BackColor = Colour
.Detail.BackColor = Colour
.FormFooter.BackColor = Colour
End With

End Sub


it's normally called as follows

ColourMeIn Forms![1-05 VIEW RELEASE].Form, Me!Rel_Type

Instead of explicitly coding the name of the form i'm trying to use a
method
of calculating the value. I can create a string that replicates the name

formname = "forms![" & me.Name & "].form"
but passing this value to the sub causes the error "ByRef argument type
mismatch"

is there anyway to convert the string to an object?
 

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