Button to select picture (1 Viewer)

swingline

Member
Local time
Today, 13:35
Joined
Feb 18, 2020
Messages
51
I am looking to add a button to a form that will allow the user to select an image file from their computer and copy it to a shared folder. Then copy the full location and paste the location into a text field on the form. Im not even sure where to start my search for something like this.
 

June7

AWF VIP
Local time
Today, 02:35
Joined
Mar 9, 2014
Messages
5,423
1. Use FileDialog to allow user to navigate to a file and select and also to navigate to and select desired destination folder

2. Use FileCopy() function to copy selected file

3. Set value of field like: Me.tbxFile = strFile
 
Last edited:

swingline

Member
Local time
Today, 13:35
Joined
Feb 18, 2020
Messages
51
1. Use FileDialog to allow user to navigate to a file and select and also to navigate to and select desired destination folder

2. Use FileCopy() function to copy selected file

3. Set value of field like: Me.tbxFile = strFile

Thanks this put me on the right path with my google searches. Here is what I came up and it is working for my needs. But, what could I add to maybe give a warning before the copy happens if the file name exists at the destination?

Code:
Option Compare Database
Private Sub Command37_Click()
Dim FileSelection As Object
Set FileSelection = Application.FileDialog(3)

Dim varFile As Variant
Dim newFCL As String

With FileSelection
.AllowMultiSelect = False

.Title = "Please Select a Figure."
.InitialFileName = "c:\"
.Filters.Clear
.Filters.Add "Any File", "*.*"
End With

If FileSelection.Show Then
For Each varFile In FileSelection.SelectedItems
newFCL = varFile
FileName = Dir(varFile)
Next
MsgBox newFCL & " copied to Z:\02.ExamBuilder\Pics."
FileCopy newFCL, "Z:\02.ExamBuilder\Pics\" & FileName
Me.FigureLocation = "Z:\02.ExamBuilder\Pics\" & FileName
Else
MsgBox "No file selected", 64, "Cancel"
Exit Sub
End If
End Sub
 

June7

AWF VIP
Local time
Today, 02:35
Joined
Mar 9, 2014
Messages
5,423
If Dir("Z:\02.ExamBuilder\Pics\" & FileName) <> "" Then
 

Users who are viewing this thread

Top Bottom