FileDilog Help Needed Please (1 Viewer)

graviz

Registered User.
Local time
Today, 15:23
Joined
Aug 4, 2009
Messages
167
I have a form with a command button that prompts the user to select a picture file. When they select it it shows the file in a label. I'm trying to have the file path they select be stored in a string so I can copy, rename, etc the file. When I used a message box to confirm it still has the value it comes up blank. I added a messagebox inside of the FOR loop and it seems to keep the value however once it's out of it it loses it and I can't seem to figure out what's going on. How could I tweak my code so I can use a string variable or exclude the for loop since they can only select one file?

Private Sub CMD_Pic_Dish_Click()
Dim fDialog As Office.FileDialog
Dim VAR_PIC_Dish As Variant
Me.LBL_Pic_Dish.Caption = ""
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
.Title = "Please select the Dish picture"
.Filters.Clear
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.bmp", 1
.Filters.Add "All Files", "*.*"
If .Show = True Then
For Each VAR_PIC_Dish In .SelectedItems
Me.LBL_Pic_Dish.Caption = VAR_PIC_Dish
MsgBox VAR_PIC_Dish
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
MsgBox VAR_PIC_Dish
End Sub

Thanks!
 

mdlueck

Sr. Application Developer
Local time
Today, 17:23
Joined
Jun 23, 2011
Messages
2,631
You have specified:

Code:
.AllowMultiSelect = False

thus you can not select multiple files.
 

graviz

Registered User.
Local time
Today, 15:23
Joined
Aug 4, 2009
Messages
167
You have specified:

Code:
.AllowMultiSelect = False

thus you can not select multiple files.

That's not the issue. I don't want them to be able to select mutiple files which is why I put that in there. I just want them to click on one and store it (the path) into a string. When I try to see the value in the message both after I exit the for loop it comes up blank. I don't really need toe loop at all do I?
 

graviz

Registered User.
Local time
Today, 15:23
Joined
Aug 4, 2009
Messages
167
That's not the issue. I don't want them to be able to select mutiple files which is why I put that in there. I just want them to click on one and store it (the path) into a string. When I try to see the value in the message both after I exit the for loop it comes up blank. I don't really need toe loop at all do I?

Just figured it out.

Private Sub CMD_Pic_Dish_Click()
Dim fDialog As Office.FileDialog
Dim VAR_PIC_Dish As String
Me.LBL_Pic_Dish.Caption = ""
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
.Title = "Please select the Dish picture"
.Filters.Clear
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.bmp", 1
.Filters.Add "All Files", "*.*"
If .Show = True Then
VAR_PIC_Dish = fDialog.SelectedItems(1)
Me.LBL_Pic_Dish.Caption = VAR_PIC_Dish
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
MsgBox VAR_PIC_Dish
End Sub
 

Users who are viewing this thread

Top Bottom