I pulled up the Tools-References. File Dialog was not there. I browsed, and could not find it. When I checked the database I downloaded, it wasn't there either. I checked everything that was checked on the downloaded database. It still didn't work.
I pulled up the Tools-References. File Dialog was not there. I browsed, and could not find it. When I checked the database I downloaded, it wasn't there either. I checked everything that was checked on the downloaded database. It still didn't work.
That means I did something wrong. This might take me a while. I'll keep you posted when I've figured it out. Thanks.
My VBA is very limited, but I'm trying. The author is doing a good job showing his work. I think I understand most of it. I'm having a problem with the last part of it. This is the FileDialog code from that database:
Dim strSearchPath As String
' Set options for the dialog box.
Dim F As FileDialog
Set F = Application.FileDialog(msoFileDialogFilePicker)
With F
.Title = "Select any image in the required folder and click on 'Open'"
.AllowMultiSelect = False
' Clear out the current filters & add our own
.Filters.Clear
.Filters.Add "Images", "*.bmp;*.gif;*.jpg;*.png;*.ico"
' Set the start folder
' By default, use existing folder ... or failing that use root folder C:\
.InitialFileName = Nz(GetFolderPath(), "C:")
' Call the Open dialog routine.
.Show
' Get the selected folder path
strSourceFolder = .SelectedItems(1)
strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, ""))
End With
The last part looks like he's getting the path and then taking only the actual name of the file (ie. Rock.jpg). Is this right?
' Get the selected folder path
strSourceFolder = .SelectedItems(1)
strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, ""))
No - it is the left, so the path, but "" should be showing a backslash which for some reason does not show when posting unless you use the code tagsThe last part looks like he's getting the path and then taking only the actual name of the file (ie. Rock.jpg). Is this right?
using code tags also preserves formatting, so please use them in the futureCode:"\"
Hi
When you post a block of code, please use the code tags (# button in the toolbar) to improve readability & fix layout issues caused by the forum software
Also please post the entire code rather than just an extract
I'm not sure whether you got this from the analystcave website or my example as all code of this type is basically the same
Whatever its source, there are a couple of issues with the code.
Particularly the part you commented on...which is incorrect
Here is a fixed version which you can test
I've added a debug line so you can see the result in the VBE Immediate window
Recommend you always do that to test your code
Good luck with your projectCode:Sub TestBrowse() Dim strSearchPath As String Dim strSourceFolder As String 'added this line ' Set options for the dialog box. Dim F As FileDialog Set F = Application.FileDialog(msoFileDialogFilePicker) With F .Title = "Select any image in the required folder and click on 'Open'" .AllowMultiSelect = False ' Clear out the current filters & add our own .Filters.Clear .Filters.Add "Images", "*.bmp;*.gif;*.jpg;*.png;*.ico" ' Set the start folder ' By default, use existing folder ... or failing that use root folder C:\ '.InitialFileName = Nz(GetFolderPath(), "C:") 'needs external function .InitialFileName = Nz(CurrentProject.Path, "C:") '<==alternative code ' Call the Open dialog routine. .Show ' Get the selected folder path strSourceFolder = .SelectedItems(1) 'strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, "")) 'ERROR HERE - just returns the entire file path strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, "\") - 1) 'modified code to get folder path Debug.Print strSourceFolder 'added to test output from code End With End Sub