Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Images    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Image Relative Path
Stephen Reynolds 
     
16 months ago
I want images to move with database, as explained in videos, and have set up the code in the examples that 1) Browse for a file 2) run a Query to remove the portion of the image path that is the CurrentProject.Path, making the path relative to the local database location and 3) display the image by adding the CurrentProject.Path back in.   What I can't get to work is how to integrate the Query in between the Browse function, and the image display.   How do I do that?    I've tried inserting a command to run the query as an update event for the field storing the image location, but it is not triggered by the Browse event which loads that data.

Alex Hedley  @Reply  
           
16 months ago
Are you not just setting the response from the file picker to the form field?
Alex Hedley  @Reply  
           
16 months ago
Did you watch
Updates
Keep Images in Folder Under Database, Use Relative Path: https://599cd.com/ImagesSubfolder
Stephen Reynolds OP  @Reply  
     
16 months ago
A: Yes, I am setting the response from the file picker to the form field, and B: Yes, I have studied that video.   The key point is to store the image location in the database without the portion of the path up to the folder the database is in (CurrentProject.Path).  The query strips the leading portion of the image path (CurrentProject.Path) so the image location becomes relative to the folder the database (and image folder) are stored in when moved.  

I want to

1) Browse and select image, returning image path to form.  - Yes, can do that

2) Strip off the leading portion of the path - the CurrentProject.Path -  and store that in the database -  Can do that with update query

3) When I want to display the picture, put the CurrentProject.Path back on the image path - Yes, can do that

I just don't know how to incorporate the query into the process.   Thanks
Stephen Reynolds OP  @Reply  
     
16 months ago
RE. my 'Step 2' above, I followed the video Store Images Relative to DB to Prevent Broken Links: https://599cd.com/blog/display-article.asp?ID=3108
Stephen Reynolds OP  @Reply  
     
16 months ago
It appears that I can do both steps 1 and 2 in the VBA code for the Browse button and eliminate the query altogether.  This seems to work -

DetailsPublic Function PickFile() As String
        Dim FO As Object
        Dim x As Variant
        Set FO = Application.FileDialog(3)
        
        If FO.Show Then
            x = FO.SelectedItems(1)
            PickFile = Replace(x, CurrentProject.Path, "")
        End If
End Function


Private Sub BtnBrowse_Click()
    Emp_Picture = PickFile()
End Sub

Stephen Reynolds OP  @Reply  
     
16 months ago
Corrected my code to also prevent overwriting existing value in table if user cancels browse -

DetailsPublic Function PickFile() As String
        Dim FO As Object
        Dim x As Variant
        Set FO = Application.FileDialog(3)
        
        If FO.Show Then
            x = FO.SelectedItems(1)
            PickFile = Replace(x, CurrentProject.Path, "")
        End If
End Function


DetailsPrivate Sub BtnBrowse_Click()
    Dim test As Variant
    test = PickFile()
    
    If test <> "" Then
        Emp_Picture = test
    End If
End Sub
Stephen Reynolds OP  @Reply  
     
16 months ago
Final update, I think.   The point of making the file references relative is to allow portability of the database.  The image files need to be copied to the image folder in the path of the database.   This code will copy a local file, found through the browse function, to the images folder in the database folder.  Whether the image comes from the images folder or elsewhere on the local machine, its name will be reduced to the relative reference.

DetailsPublic Function PickFile() As String
  
        Dim FO As Object
        Dim FSO As Object
        Dim sFilename As String
        Dim x As Variant
        
        Set FSO = VBA.CreateObject("Scripting.FileSystemObject")
        Set FO = Application.FileDialog(3)    
        If FO.Show Then
            x = FO.SelectedItems(1)            
            sFilename = Mid$(x, InStrRev(x, "\") + 1)            
            If InStr(x, [CurrentProject].[Path]) = 0 Then          
                Call FSO.CopyFile(x, [CurrentProject].[Path] & "\images\", True)
                PickFile = "\images\" & [sFilename]              
            Else          
                PickFile = Replace(x, CurrentProject.Path, "")                
            End If                      
        End If        

End Function


DetailsPrivate Sub BrowseBtn_Click()

    Dim test As Variant
    test = PickFile()    
    If test <> "" Then
        Org_Image_Link = test
    End If
  
End Sub

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

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/10/2026 8:12:50 AM. PLT: 1s