Passing Form Reference as Me

G

Guest

I designed a database application with approximately 30 forms in it. Now, the
powers that be decided that they want the appearance of the forms to be
different, but the functionality is ok. Each form has a header with a label
lblFormTitle and a footer with an image control imgCompanyLogo. I am trying
to write a module that has a SetFormAppearance() function, that each form can
call on load to set properties such as imgCompanyLogo.Picture,
lblFormTitle.Font, etc. I would also like to be able to set the Header and
Footer Section heights as well. The code I have below is incomplete (in that
there are other properties I would like to set, but I think I have a
representative few selected so far), but it still crashes out. I call it as
SetFormAppearance(Me) in the load event code for each form (well, a single
form at this point, but once it works it will be in all forms). The error it
generates is "438 - Object doesn't support this property or method". While I
am not certain about the syntax for header height, the code to set the
picture sources works elsewhere in the database as "Me.Form.Picture = ..."
Any thoughts? Thanks,

Matt


Public Sub SetFormAppearance(frm As Form)
' Set form background, header and footer control properties
On Error GoTo SetFormAppearance_Error

' Constant for error handling
Const conImageFilesNotFound = 2220

' Set form background
frm.Form.Picture = Nz(DLookup("[PathFormBackGround]", "[tblPaths]"),
"????")

' Set header properties
frm.FormHeader.Height = 0.4271 'InchesToTwips(0.4271)
frm.lblFormTitle.Left = 0.5 'InchesToTwips(0.5)

' Set footer properties
frm.imgCompanyLogo.Picture = Nz(DLookup("[PathBCTLogo]", "[tblPaths]"),
"????")

SetFormAppearance_Exit:
Exit Sub

SetFormAppearance_Error:
Select Case Err
Case conImageFilesNotFound
Resume Next
Case Else
MsgBox Err.Number & " - " & Err.Description
'CloseCurrentDatabase
'Resume SetFormAppearance_Exit
Resume Next
End Select

End Sub


Public Function InchesToTwips(dblInches As Double) As Integer
InchesToTwips = Int(dblInches * 1440) '(1440 twips per in)
End Function
 
A

Andrew Backer

Have you tried :
SetFormAppearance(Me.Form)?

Also, if you have to, you can pass in the name of the form (since it's
open) and then look in the Forms("...") collection, but thats ugly.

- Andrew Backer
 
D

Douglas J. Steele

Is SetFormAppearance(Me) literally what you have?

If so, try

SetFormAppearance Me

or

Call SetFormAppearance(Me)
 
G

Guest

Where exactly does it fail?

BTW, that frm.Form. syntax is not required.

'Me' (the VBA object) has a property for [Form], the property
of a form that points to itself, because it has object properties for all
the important form properties, but for most VBA coding, Me.Form
is like Me.Me.

The form has a property that points to itself because (a) it was
required in Access before the Me object was introduced, and
(b) because it is required in Access macro's and control properties,
where VBA objects are not visible.

(david)
 
G

Guest

I figured it out... I needed to declare

Public Sub SetFormAppearance(frm As Variant)
With frm.Parent
' Everything else now references correctly
End With
End Sub

Thanks for the suggestions though!

david@epsomdotcomdotau said:
Where exactly does it fail?

BTW, that frm.Form. syntax is not required.

'Me' (the VBA object) has a property for [Form], the property
of a form that points to itself, because it has object properties for all
the important form properties, but for most VBA coding, Me.Form
is like Me.Me.

The form has a property that points to itself because (a) it was
required in Access before the Me object was introduced, and
(b) because it is required in Access macro's and control properties,
where VBA objects are not visible.

(david)



MartinMCU said:
I designed a database application with approximately 30 forms in it. Now, the
powers that be decided that they want the appearance of the forms to be
different, but the functionality is ok. Each form has a header with a label
lblFormTitle and a footer with an image control imgCompanyLogo. I am trying
to write a module that has a SetFormAppearance() function, that each form can
call on load to set properties such as imgCompanyLogo.Picture,
lblFormTitle.Font, etc. I would also like to be able to set the Header and
Footer Section heights as well. The code I have below is incomplete (in that
there are other properties I would like to set, but I think I have a
representative few selected so far), but it still crashes out. I call it as
SetFormAppearance(Me) in the load event code for each form (well, a single
form at this point, but once it works it will be in all forms). The error it
generates is "438 - Object doesn't support this property or method". While I
am not certain about the syntax for header height, the code to set the
picture sources works elsewhere in the database as "Me.Form.Picture = ..."
Any thoughts? Thanks,

Matt


Public Sub SetFormAppearance(frm As Form)
' Set form background, header and footer control properties
On Error GoTo SetFormAppearance_Error

' Constant for error handling
Const conImageFilesNotFound = 2220

' Set form background
frm.Form.Picture = Nz(DLookup("[PathFormBackGround]", "[tblPaths]"),
"????")

' Set header properties
frm.FormHeader.Height = 0.4271 'InchesToTwips(0.4271)
frm.lblFormTitle.Left = 0.5 'InchesToTwips(0.5)

' Set footer properties
frm.imgCompanyLogo.Picture = Nz(DLookup("[PathBCTLogo]", "[tblPaths]"),
"????")

SetFormAppearance_Exit:
Exit Sub

SetFormAppearance_Error:
Select Case Err
Case conImageFilesNotFound
Resume Next
Case Else
MsgBox Err.Number & " - " & Err.Description
'CloseCurrentDatabase
'Resume SetFormAppearance_Exit
Resume Next
End Select

End Sub


Public Function InchesToTwips(dblInches As Double) As Integer
InchesToTwips = Int(dblInches * 1440) '(1440 twips per in)
End Function
 

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