Open specific folder to link image (1 Viewer)

Robb58

Registered User.
Local time
Today, 16:19
Joined
Sep 4, 2014
Messages
28
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:19
Joined
Oct 29, 2018
Messages
21,358
Hi. I think it’s something like

.InitialFileName = YourFolderNameHere

Hope it helps...
 

Robb58

Registered User.
Local time
Today, 16:19
Joined
Sep 4, 2014
Messages
28
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:19
Joined
Oct 29, 2018
Messages
21,358
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’t forget to pecede it with the f. Object. For example, f.InitialFileName
 

Robb58

Registered User.
Local time
Today, 16:19
Joined
Sep 4, 2014
Messages
28
Hi. Try to put it after the .AllowMultiselect and don’t 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 :confused:
 

Robb58

Registered User.
Local time
Today, 16:19
Joined
Sep 4, 2014
Messages
28
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:banghead::eek:
 

Robb58

Registered User.
Local time
Today, 16:19
Joined
Sep 4, 2014
Messages
28
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 :confused:
 

isladogs

MVP / VIP
Local time
Today, 16:19
Joined
Jan 14, 2017
Messages
18,186
I think I followed that....:D
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:19
Joined
Oct 29, 2018
Messages
21,358
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:banghead::eek:
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...
 

Robb58

Registered User.
Local time
Today, 16:19
Joined
Sep 4, 2014
Messages
28
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. :eek:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:19
Joined
Oct 29, 2018
Messages
21,358
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. :eek:
Hi. Glad to hear you got it to work. Good luck with your project.
 

MarathonManErnst

New member
Local time
Today, 17:19
Joined
Feb 27, 2020
Messages
3
Hi,

How can you save multiple selected items with this code in your database and then have them alternate in view mode in your database every couple seconds?:

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


Thanks in advance!!

MarathonManErnst
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:19
Joined
Oct 29, 2018
Messages
21,358
Hi. To alternate the images displayed on a form, you can use the Timer Event. What exactly are you trying to accomplish?
 

MarathonManErnst

New member
Local time
Today, 17:19
Joined
Feb 27, 2020
Messages
3
to add 2 or 3 (sometimes 4) images to 1 record. Like with a book database, you have the cover and backcover to show. Sometimes you also want to show off the autograph of the author ;) If I use that code I can select multiple items but when the program writes the location and file name in the database it overwrites the first 1 when doing the second picture.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:19
Joined
Oct 29, 2018
Messages
21,358
to add 2 or 3 (sometimes 4) images to 1 record. Like with a book database, you have the cover and backcover to show. Sometimes you also want to show off the autograph of the author ;) If I use that code I can select multiple items but when the program writes the location and file name in the database it overwrites the first 1 when doing the second picture.
So, you will have to create multiple records in your table to store the many images. May I suggest starting a new thread to focus on your specific needs and have a better chance of getting more help? Cheers!
 

Users who are viewing this thread

Top Bottom