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!
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!