Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-13-2019, 05:04 AM   #1
Robb58
Newly Registered User
 
Join Date: Sep 2014
Posts: 28
Thanks: 15
Thanked 0 Times in 0 Posts
Robb58 is on a distinguished road
Open specific folder to link image

I have a database that has a button on the record form that will create folder using the record number using the following code:

Code:
Private Sub CreateFolder_Click()
' In Microsoft Windows:
' Specifying 1 as the second argument opens the application in
' normal size and gives it the focus.
Dim RetVal
Dim FolderName As String

FolderName = Format(Me.Job_Number, "00000")

RetVal = Shell("cmd.exe /C color 4e && md G:\Jobs\" & FolderName, 1)  ' Create graphics Job folder.
MsgBox "The folder G:\Jobs" & FolderName & " has been created.  You should use this folder to store all files related to this finished Job.  When the job is complete ensure you clear up any other files stored on the network, so as to conserve storage space.", vbOKOnly, "Folder Created"

End Sub
and uses the following code to open the folder relating to the record number:
Code:
Private Sub View_Folder_Click()
Dim RetVal
Dim FolderName As String

FolderName = Format(Me.Job_Number, "00000")

RetVal = Shell("explorer G:\Jobs\" & FolderName, 1)  ' View Job folder
I want to be able to add an image to the form by browsing to the record related folder and selecting an image so all relevant information is contained in the same folder. At the moment I have a code attached to a button which works well and allows me to browse and link the photo, but it just opens up a standard Explorer window which I then have to navigate around to find the folder correlating to the record number. Is there a way to open directly to the record specific folder to link the Image to minimise the need for navigating? The current browse for image code is below:
Code:
Private Sub BrowseImge_button_Click()

    Dim f As Object
    Dim strfile As String
    Dim strfolder As String
    Dim VarItem As Variant
    
    
    Set f = Application.FileDialog(3)
    f.allowMultiSelect = True
    If f.Show Then
    For Each VarItem In f.selectedItems
    strfile = Dir(VarItem)
    
    strfolder = Left(VarItem, Len(VarItem) - Len(strfile))
    MsgBox "Folder" & strfolder & vbCrLf & "File: " & strfile
    
    Image_Source_TXT = strfolder + strfile
    Next
    End If
End Sub

Robb58 is offline   Reply With Quote
Old 08-13-2019, 05:14 AM   #2
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,631
Thanks: 38
Thanked 885 Times in 868 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Open specific folder to link image

Hi. I think it’s something like

.InitialFileName = YourFolderNameHere

Hope it helps...
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
Robb58 (08-13-2019)
Old 08-13-2019, 05:21 AM   #3
Robb58
Newly Registered User
 
Join Date: Sep 2014
Posts: 28
Thanks: 15
Thanked 0 Times in 0 Posts
Robb58 is on a distinguished road
Re: Open specific folder to link image

hi theDBguy
thanks for the suggestion - where would that code go. Sorry, I'm a bit of cut and paste guy when it comes to VBA lol

Robb58 is offline   Reply With Quote
Old 08-13-2019, 05:52 AM   #4
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,631
Thanks: 38
Thanked 885 Times in 868 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Open specific folder to link image

Quote:
Originally Posted by Robb58 View Post
hi theDBguy
thanks for the suggestion - where would that code go. Sorry, I'm a bit of cut and paste guy when it comes to VBA lol
Hi. Try to put it after the .AllowMultiselect and don稚 forget to pecede it with the f. Object. For example, f.InitialFileName
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 08-13-2019, 06:15 AM   #5
Robb58
Newly Registered User
 
Join Date: Sep 2014
Posts: 28
Thanks: 15
Thanked 0 Times in 0 Posts
Robb58 is on a distinguished road
Re: Open specific folder to link image

Quote:
Originally Posted by theDBguy View Post
Hi. Try to put it after the .AllowMultiselect and don稚 forget to pecede it with the f. Object. For example, f.InitialFileName
I tried your suggestion without any success - not sure what I'm missing
Robb58 is offline   Reply With Quote
Old 08-13-2019, 06:29 AM   #6
Insane_ai
Not Really an A.I.
 
Join Date: Mar 2009
Location: Cleveland, OH USA
Posts: 245
Thanks: 14
Thanked 25 Times in 22 Posts
Insane_ai is on a distinguished road
Re: Open specific folder to link image

Give this a read, it covers the file dialogue pretty well.

https://analystcave.com/vba-application-filedialog-select-file/
__________________
I actually know a few things, just not all of them.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Insane_ai is offline   Reply With Quote
The Following User Says Thank You to Insane_ai For This Useful Post:
Robb58 (08-14-2019)
Old 08-13-2019, 07:12 AM   #7
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,631
Thanks: 38
Thanked 885 Times in 868 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Open specific folder to link image

Quote:
Originally Posted by Robb58 View Post
I tried your suggestion without any success - not sure what I'm missing
Hi. Can you show us exactly how you tried it? Thanks.

__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 08-14-2019, 02:20 AM   #8
Robb58
Newly Registered User
 
Join Date: Sep 2014
Posts: 28
Thanks: 15
Thanked 0 Times in 0 Posts
Robb58 is on a distinguished road
Re: Open specific folder to link image

Quote:
Originally Posted by theDBguy View Post
Hi. Can you show us exactly how you tried it? Thanks.
I've ditched the new code and gone back to my original code for now which works but doesn't navigate to the report related folder. I put it where you suggested (.AllowMultiselect) and made sure to include the "f.", but I think there probably needs to be extra code.

Based on my initial codes what should the value be after ".InitialFileName ="?

Apologies for being so dim
Robb58 is offline   Reply With Quote
Old 08-14-2019, 03:45 AM   #9
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 9,824
Thanks: 107
Thanked 2,660 Times in 2,434 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: Open specific folder to link image

Perhaps my example database will help Folder Image Viewer
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
Robb58 (08-14-2019)
Old 08-14-2019, 04:54 AM   #10
Robb58
Newly Registered User
 
Join Date: Sep 2014
Posts: 28
Thanks: 15
Thanked 0 Times in 0 Posts
Robb58 is on a distinguished road
Re: Open specific folder to link image

Quote:
Originally Posted by isladogs View Post
Perhaps my example database will help Folder Image Viewer
thank you Colin. Using the "BrowseImge_button_Click()" command I'm able to select an image to populate the "Image_Source_TXT" which gets stored in a field on a table which then loads the selected image into an image holder on the form, so I know the code for the "BrowseImge_button" works. However, it's a bit of a blunt tool in that it opens a general Explorer window.

Ideally I need it to be more targeted so open the folder which is generated by the "CreateFolder"_Click()" code and accessed via the "View_Folder_Click()" code (see oringinal post). This folder is used to store all of the files related to the artwork requirement described in the record number (Me.Job_Number). The image displayed will be an example of the artwork in the folder so, for ease of locating the image, somewhere in the button code I need it to direct to the correct job number related folder.

I hope that's not too confusing
Robb58 is offline   Reply With Quote
Old 08-14-2019, 05:03 AM   #11
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 9,824
Thanks: 107
Thanked 2,660 Times in 2,434 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: Open specific folder to link image

I think I followed that....
If the following misses the point then you'll know I didn't after all.

When you create the folder, save the folder path as a variable then use that value to open that folder direct and then choose the appropriate image from the file.

The other approach is to just store the path for each image file in a table along with the job number then have your image control(s) set to that path
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 08-14-2019, 06:50 AM   #12
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,631
Thanks: 38
Thanked 885 Times in 868 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Open specific folder to link image

Quote:
Originally Posted by Robb58 View Post
I've ditched the new code and gone back to my original code for now which works but doesn't navigate to the report related folder. I put it where you suggested (.AllowMultiselect) and made sure to include the "f.", but I think there probably needs to be extra code.

Based on my initial codes what should the value be after ".InitialFileName ="?

Apologies for being so dim
Hi. If the above question is already moot, please ignore my reply. I just wanted to make sure you know I'm not ignoring you. So, to answer the above question, I would have probably tried something like this:
Code:
f.InitialFileName = "G:\Jobs\" & Format(Me.Job_Number, "00000")
Hope it helps...
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
Robb58 (08-15-2019)
Old 08-15-2019, 12:42 AM   #13
Robb58
Newly Registered User
 
Join Date: Sep 2014
Posts: 28
Thanks: 15
Thanked 0 Times in 0 Posts
Robb58 is on a distinguished road
Thumbs up Re: Open specific folder to link image

Quote:
Originally Posted by theDBguy View Post
Hi. If the above question is already moot, please ignore my reply. I just wanted to make sure you know I'm not ignoring you. So, to answer the above question, I would have probably tried something like this:
Code:
f.InitialFileName = "G:\Jobs\" & Format(Me.Job_Number, "00000")
Hope it helps...
That worked a treat, Many thanks, you're a star theDBguy . I'm sure I tried something like that but it failed so I obviously had some sort of syntax error.
Robb58 is offline   Reply With Quote
Old 08-16-2019, 08:42 AM   #14
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,631
Thanks: 38
Thanked 885 Times in 868 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: Open specific folder to link image

Quote:
Originally Posted by Robb58 View Post
That worked a treat, Many thanks, you're a star theDBguy . I'm sure I tried something like that but it failed so I obviously had some sort of syntax error.
Hi. Glad to hear you got it to work. Good luck with your project.

__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Reply

Tags
folder browser , link files

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Command to Open Folder Using File Path Link cmcd29 Modules & VBA 5 09-29-2015 07:04 AM
Question Open a specific Windows Folder DREAMERMX General 10 08-15-2013 02:36 PM
Open Specific Folder robbydogg Modules & VBA 2 05-21-2010 02:37 AM
Link to a specific Subfolder Name located in a specific Folder Name dim1962 Forms 3 03-24-2009 12:20 PM
Open specific hard drive folder Smee Modules & VBA 2 06-29-2004 06:00 AM




All times are GMT -8. The time now is 02:56 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World