473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

FileDialog box and preventing browsing

Hi

I specify the initial location of my Application.FileDialog(msoFileDialogFilePicker) box by setting the initialFileName property to the location I want the user to pick a file from.

So far so good, but is it possible to prevent users from being able to browse to another dir?
I would like to be able to restrict them to the location I specify!

Any thoughts?

Thanks
Rob
Feb 14 '08 #1
4 3868
Delerna
1,134 Expert 1GB
Havent looked specifically so here is a general description of what I would try.

The file dialog control should have an event that fires when the directory is chosen.

In the code for that event you would check to see if the user has left the allowed directory.
If they have then you would reset the path back to the one that you want them to be stuck in and refresh the controls display.

Something like that anyway!
Feb 14 '08 #2
Scott Price
1,384 Expert 1GB
This is a quick and dirty code sample that checks for a specified path in the selected item, if the user selected a file from another location it pops up a message box.

Expand|Select|Wrap|Line Numbers
  1.    Dim dlgOpen As FileDialog
  2.    Dim varSelectedItem As Variant
  3.    Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
  4.  
  5.    With dlgOpen
  6.         If .Show = True Then
  7.             For Each varSelectedItem In .SelectedItems
  8.                 If Left(varSelectedItem, 15) <> "E:\Access Code\" Then
  9.                     MsgBox ("Please select a valid path")
  10.                 End If
  11.             Next varSelectedItem
  12.         End If
  13.  
  14.    End With
Unfortunately I don't know of any way to limit the browse ability of the dialog box in Access. Your users will be able to browse to whichever location they wish, but this will prevent them from opening the file if it isn't in the directory you specify.

You'll need to add the execute command in order to make Access open a valid file.

Regards,
Scott
Feb 14 '08 #3
Thanks very much, Scott and Delerna

It works well, and for my purpose it will be acceptable to remind users not to stray away from the directory they are supposed to use.
Unfortunately, the FileDialog closes when they OK the msgbox - I'll try to tweak your code to keep it open and as Delerna had suggested, navigate them back to the propper dir.

Thanks again

Rob







This is a quick and dirty code sample that checks for a specified path in the selected item, if the user selected a file from another location it pops up a message box.

Expand|Select|Wrap|Line Numbers
  1.    Dim dlgOpen As FileDialog
  2.    Dim varSelectedItem As Variant
  3.    Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
  4.  
  5.    With dlgOpen
  6.         If .Show = True Then
  7.             For Each varSelectedItem In .SelectedItems
  8.                 If Left(varSelectedItem, 15) <> "E:\Access Code\" Then
  9.                     MsgBox ("Please select a valid path")
  10.                 End If
  11.             Next varSelectedItem
  12.         End If
  13.  
  14.    End With
Unfortunately I don't know of any way to limit the browse ability of the dialog box in Access. Your users will be able to browse to whichever location they wish, but this will prevent them from opening the file if it isn't in the directory you specify.

You'll need to add the execute command in order to make Access open a valid file.

Regards,
Scott
Feb 14 '08 #4
Scott Price
1,384 Expert 1GB
It's not really the accepted practice since MS is moving away from the GoTo command, but you could set a label on the line where the With dlgOpen statement starts, and then set a GoTo [Label]: statement after the message box. This forces it back through the loop and reopens the dialog box after an incorrect choice.

I just set it up in my test database using 9: as the label for line number 9 (where the With statement starts), then put GoTo 9: in the next line after the message box.

Regards,
Scott
Feb 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: geradeaus | last post by:
Hi, I use a php class to create pdf files (http://www.ros.co.nz/pdf/) ... but when I download the created pdf, the browser window closes, and Acrobat opens. How do I prevent the closing of...
4
by: ulysses | last post by:
Hi, I use PyQt 3.8 non-commercial version in win32. I get a big question. I Can't show PY variable in QT filedialog as initially parameter. Code sample is following:...
3
by: John Field | last post by:
Hello, Is it possible to exclude certain files in a wx.FileDialog, so that the user won't see them and can't select them with the mouse in de File open window? I was thinking of somehow...
2
by: zino | last post by:
I'm using the following code to get the file name and path, but after the user click the file, Excel open it. I don't want the Excel file to open, all I need is to get the file name that the user...
3
by: samadams_2006 | last post by:
I have a Web Site that I'm interested in selling eBooks from. I'm having a problem setting it up as I would like, and hope that someone can help me out. Inside my domain I have a folder called...
3
by: David Bib | last post by:
Although I'm relatively new to Access VBA, I've done a lot of macro programming in Excel VBA. The problem I'm having is that I get a 'User Type not defined' error at this line - Dim fd As...
2
by: akmagnolia | last post by:
Hello- I am trying to use the FileDialog object to allow users to select a file. When I compile, I get the User type not defined error at the first DIM statement. My code is copied right out of the...
2
jamjar
by: jamjar | last post by:
I am trying to use the SaveAs type FileDialog to allow the user to enter a file name. It's only letting me choose exisiting files. Is there any way to use the FileDialog to allow the user to select...
1
by: evenlater | last post by:
I have an Access 2007 application running on a terminal server. One of the features of the app is a wizard that allows them to create an Excel spreadsheet by querying the Access data. When they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.