Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Form object properties not set
Jennifer Neighbors 
     
3 years ago
I am working on an app where the user can select a screen background from a set of choices. The background chosen may be looked up in a table. The background images are stored in the same folder as my access db file. I link to the chosen background image when each form is loaded. I have a procedure in each form's on-load event to do this, and it works perfectly.

However, I want to make my code more efficient using a global procedure. Doing so requires passing the form as an object to the global procedure ("me.form") so the global procedure knows which form is calling.

In the global procedure, the form object's properties cannot be set, however. This code doesn't work:


Sub SetFormBackground(oForm As Object)

Dim path As String
Dim PicName As String

path = CurrentProject.path
PicName = DLookup("Background", "tblBackgrounds", "ChooseThisOne = True")

With oForm
  .Picture = path & "\" & PicName
  .PictureAlignment = 3
End With

End Sub


I get runtime error 438 - Object doesn't support this property or method.

This isn't a particularly complex procedure! I could just leave this in each form's module, where I can easily work with the form properties, but I'm curious now. How can I set a form's properties from a global module dynamically?
Kevin Robertson  @Reply  
           
3 years ago
Are you using parentheses when calling SetFormBackground?
They are not needed since it's not a function.

SetFormBackground Me.Form

or

SetFormBackground Me

You could also send the Form Name as a string:

Sub SetFormBackground(FormName As String)

    Dim path As String
    Dim PicName As String
    
    path = CurrentProject.path
    PicName = DLookup("Background", "BackgroundT", "ChooseThisOne = True")
    
    With Forms(FormName)
      .Picture = path & "\" & PicName
      .PictureAlignment = 3
    End With

End Sub


Then in your form: SetFormBackground Me.Name

A couple of options.
Jennifer Neighbors OP  @Reply  
     
3 years ago
Your version works perfectly! I also tried passing the string variable but got tripped up in the syntax of the "with...end with" clause. You've clarified how to write that, and it's far more straightforward than I thought. Thank you so much!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developers.
 

Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 9/6/2026 4:07:02 AM. PLT: 1s