Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Global Module
Colin Smyth 
      
5 years ago
In your extended cut for using the Browse button to find a file path for a picture, you say that if you want to use it more than once, then you need to put the first part of the code in a global module. Can you tell me how to do that?
Adam Schwanz  @Reply  
           
5 years ago
In Access, go to Create then click Module.

You can use Public Sub or Public Function in these and then can call them from anywhere in the database.
Colin Smyth OP  @Reply  
      
5 years ago
Thank you Adam. I am new to VBA. How do I call it from somewhere in the database - what do I need type.
Alex Hedley  @Reply  
           
5 years ago
Adam Schwanz  @Reply  
           
5 years ago
Yea watch the video Alex gave you, it's usage will depend on what you want it to do and if it's a simple command or if you're sending it variables to do things with.

For instance you could say

Public Function MyRefresh
  Me.Refresh
End Function

and then in your code you could say like

Private Sub TestBtn_Click
  MyRefresh
End Sub
Colin Smyth OP  @Reply  
      
5 years ago
Thank you Alex and Adam. I have watched the videos but still not clear.
The code in question was as Richard gave it was:

Public Function Pickfile() As String
    Dim FO As Object
    Set FO = Application.FileDialog(3)
    FO.Show
    Pickfile = FO.selecteditems(1)

End Function

Then on click on a button, I want it to say
Photo2 = Pickfile()

So that it finds that file.
But on another button

Photo3 = Pickfile()    which then picks out a different file

I have tried what I thought you meant Adam, but it brings up an error.

Any advice would be appreciated. Thank you
Alex Hedley  @Reply  
           
5 years ago
Can you share the error?
Colin Smyth OP  @Reply  
      
5 years ago
Hi Alex. Since I sent the above post, I added the following to the click button:

Me.Pickfile
Photo3 = Pickfile()

This works to some degree, in that it lets me go to be able to choose the file. I choose it and then it takes me back to the same place and then when I choose the same file again, it adds it to the form like it is suppose to. So no error now, but not sure why I have to choose it twice for it to be selected.

Thanks for your help
Richard Rost  @Reply  
          
5 years ago
Get rid of Me.Pickfile.
Colin Smyth OP  @Reply  
      
5 years ago
Thank you Richard. I thought I had tried that before but it wouldn't work but it does now. I have a database for photos of birds that I have taken. For each bird there is an option of 5 different photos to display. They have all been set up the same, so the file that is added showing where the photograph is on my hard drive is then linked to an image file with the e:\bird etc as the control source for the image. They all now work apart from one where I get the following error message

Runtime error 438
Object doesn't support this property or method

I have set each image exactly the same. The code all seems the same. I deleted that particular image and started again but still get the same error. Can you give me any suggestions - the rest all works really well. Doing it this way, has certainly shrunk my database file significantly because before I had the photos as attachments.
Thank you
Adam Schwanz  @Reply  
           
5 years ago
Are you saying just one photo you have doesn't work or one of the 5 photos always doesn't work?

Is that just photo5=pickfile()

If its a single photo what is the photoname? You could have a name with a reserved word or character that breaks the code.
Scott Axton  @Reply  
        
5 years ago
Colin,  rather than play 20 questions, it is often helpful if you post screen shots of your form, code behind it, etc that would help us visualize what you are doing.  

You can upload screen shots via the original post in the upper right hand corner.
Walk us through step by step what you do to generate the error like we were 3rd graders.
Is this something that is random or is it something that every time I do A, B, C, then X happens?

Colin Smyth OP  @Reply  
      
5 years ago

Colin Smyth OP  @Reply  
      
5 years ago
Thanks Adam and Scott. They all work but on every bird, Photo3 doesn't - so always the same one.
Alex Hedley  @Reply  
           
5 years ago
What are the names of the controls on the Form?
Colin Smyth OP  @Reply  
      
5 years ago

Colin Smyth OP  @Reply  
      
5 years ago
So the Textbox called Photo3 etc is where the photo on my computer is stored which the browse button imports. The highlighted square is the image box that I have placed there with the Control Source of Photo3. They are all the same and the others all work apart from this one.
Colin Smyth OP  @Reply  
      
5 years ago
Hi Alex. I am sorry, I have partly solved the problem. There was another Image file on another page of the form which I wasn't using and had forgotten about, with the same name as Photo3. I have now deleted that. The programme now captures the file on my computer and appears to do nothing but when I change to another bird and then come back to the original bird, the photo and the link to the computer file now shows. The others all happen instantly but at least it is working - I can live with that.
Colin Smyth OP  @Reply  
      
5 years ago
Hi Alex. On Photo3 after the Photo3 = Pickfile(), I added the code Docmd.RefreshRecord and it now all works. Thank you for your patience. Still struggling with the various options in VBA. Thanks again

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

Next Unseen

 
New Feature: Comment Live View
 
 

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: 5/7/2026 6:21:19 AM. PLT: 5s