473,503 Members | 12,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Limiting what shows up in 'Browse' dialogue

110 New Member
Hello,

This time I want to filter the 'browse for file' API so that certain drives/folders cant be accessed.

Not sure how to go about this...here is the module I am currently using to browse for a file then return the file link...

any ideas/help are highly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3.  
  4. Private Type OPENFILENAME
  5.     lStructSize As Long
  6.     hwndOwner As Long
  7.     hInstance As Long
  8.     lpstrFilter As String
  9.     lpstrCustomFilter As Long
  10.     nMaxCustrFilter As Long
  11.     nFilterIndex As Long
  12.     lpstrFile As String
  13.     nMaxFile As Long
  14.     lpstrFileTitle As String
  15.     nMaxFileTitle As Long
  16.     lpstrInitialDir As String
  17.     lpstrTitle As String
  18.     Flags As Long
  19.     nFileOffset As Integer
  20.     nFileExtension As Integer
  21.     lpstrDefExt As String
  22.     lCustrData As Long
  23.     lpfnHook As Long
  24.     lpTemplateName As Long
  25. End Type
  26.  
  27. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
  28.     "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Boolean
  29.  
  30. Private strDialogTitle As String
  31. Private intDefaultType As Integer
  32. Private strNewTypes As String
  33. Private strInitialFile As String
  34. Private strInitialDir As String
  35. Private strFilter As String
  36. Private strFltrLst As String
  37. Private strFltrCnt As String
  38.  
  39.  
  40.  
  41. '   This 'Method' routine displays the Open dialog box for the user to
  42. '   locate the desired file.  Returns the full path to the file.
  43. '
  44. Public Function GetFileSpec()
  45.     Dim of As OPENFILENAME
  46.     Dim intRet As Integer
  47.  
  48.                     'set up the file filter and the default type option
  49.     If strNewTypes <> "" Then
  50.         of.lpstrFilter = strNewTypes & strFilter
  51.         of.nFilterIndex = 1
  52.     Else
  53.         of.lpstrFilter = strFilter
  54.         If intDefaultType <> 0 Then
  55.             of.nFilterIndex = intDefaultType
  56.         Else
  57.             of.nFilterIndex = 1
  58.         End If
  59.     End If
  60.                     'define some other dialog options
  61.     of.lpstrTitle = strDialogTitle
  62.     of.lpstrInitialDir = strInitialDir
  63.     of.lpstrFile = strInitialFile & String(512 - Len(strInitialFile), 0)
  64.     of.nMaxFile = 511
  65.  
  66.                     ' Initialize other parts of the structure
  67.     of.hwndOwner = Application.hWndAccessApp
  68.     of.hInstance = 0
  69.     of.lpstrCustomFilter = 0
  70.     of.nMaxCustrFilter = 0
  71.     of.lpfnHook = 0
  72.     of.lpTemplateName = 0
  73.     of.lCustrData = 0
  74.     of.lpstrFileTitle = String(512, 0)
  75.     of.nMaxFileTitle = 511
  76.     of.lpstrDefExt = vbNullChar
  77.     of.Flags = 0
  78.     of.lStructSize = Len(of)
  79.  
  80.                     'call the Open dialog routine
  81.     intRet = GetOpenFileName(of)
  82.     If intRet Then
  83.         GetFileSpec = Left(of.lpstrFile, InStr(of.lpstrFile, vbNullChar) - 1)
  84.     Else
  85.         GetFileSpec = ""
  86.     End If
  87.  
  88. End Function    'End of GetFileSpec
  89.  
  90.  
  91. '
  92. '   The following 'Property' routines define the Dialog Box properties
  93. '
  94.  
  95. Public Property Let DialogTitle(strTitle As String)
  96.                 'store the title for the dialog box
  97.     strDialogTitle = strTitle
  98. End Property
  99.  
  100. Public Property Let AdditionalTypes(strAddTypes As String)
  101.     Dim posn As Integer
  102.     Dim i As Integer
  103.  
  104.                     'don't accept additional types if a default type has been specified
  105.     If intDefaultType <> 0 Then
  106.         MsgBox "You cannot use both the AdditionalTypes property (to add to the " & _
  107.                 "file type filter) and the DefaultType property (to select which " & _
  108.                 "file type will be the default).  When the AdditionalTypes property " & _
  109.                 "is used, the first file type in that property " & _
  110.                 "is used as the default in the file type filter.", vbCritical, _
  111.                 "Browse For File Dialog"
  112.         Exit Property
  113.     End If
  114.                     'check for the "|" delimiter
  115.     posn = InStr(strAddTypes, "|")
  116.                     'save the new parameter or report an error
  117.     If posn = 0 Then
  118.         MsgBox "The AdditionalTypes property string does not contain at least " & _
  119.                 "one " & Chr$(34) & "|" & Chr$(34) & " character.  " & _
  120.                 "You must specify an AdditionalTypes property in the same " & _
  121.                 "format that is shown in the " & _
  122.                 "following examples: " & vbCrLf & vbCrLf & Chr$(34) & _
  123.                 "Rich Text Files (*.rtf) | *.rtf" & Chr$(34) & vbCrLf & Chr$(34) & _
  124.                 "My Files (*.mf1;*.mf2) | *.mf1;*.mf2 | " & _
  125.                 "Your File (*.yrf) | *.yrf" & Chr$(34), vbCritical, _
  126.                 "Browse For File Dialog"
  127.  
  128.         strNewTypes = ""
  129.         Exit Property
  130.     Else
  131.         Do While True
  132.             If posn > 0 Then
  133.                 strNewTypes = strNewTypes & Left$(strAddTypes, posn - 1) & vbNullChar
  134.                 strAddTypes = Mid$(strAddTypes, posn + 1)
  135.                 posn = InStr(1, strAddTypes, "|")
  136.             Else
  137.                 strNewTypes = strNewTypes & vbNullChar
  138.                 Exit Do
  139.             End If
  140.         Loop
  141.     End If
  142.  
  143. End Property    'End of AdditionalTypes
  144.  
  145. Public Property Let DefaultType(strType As String)
  146.     Dim posn As Integer
  147.  
  148.     posn = InStr(strFltrLst, strType)
  149.  
  150.                 'don't accept a default if new types are being specified
  151.     If strNewTypes <> "" Then
  152.         MsgBox "You cannot use both the AdditionalTypes property (to add to the " & _
  153.                 "file type filter) and the DefaultType property (to select which " & _
  154.                 "file type will be the default).  When the AdditionalTypes property " & _
  155.                 "is used, the first file type in that property " & _
  156.                 "is used as the default in the file type filter.", vbCritical, _
  157.                 "Browse For File Dialog"
  158.         Exit Property
  159.                 'make sure the selected default actually exists
  160.     ElseIf posn = 0 Then
  161.         MsgBox "The file type you specified in the DefaultType " & _
  162.                 "property is not in the built-in " & _
  163.                 "list of file types.  You must either specify one of the " & _
  164.                 "built-in file types or use the AdditionalTypes property " & _
  165.                 "to specify a complete entry similar to the " & _
  166.                 "following examples: " & vbCrLf & vbCrLf & Chr$(34) & _
  167.                 "Rich Text Files (*.rtf) | *.rtf" & Chr$(34) & vbCrLf & Chr$(34) & _
  168.                 "My Files (*.mf1;*.mf2) | *.mf1;*.mf2 | " & _
  169.                 "Your File (*.yrf) | *.yrf" & Chr$(34), vbCritical, _
  170.                 "Browse For File Dialog"
  171.         Exit Property
  172.     Else
  173.                 'set up the selected default
  174.         intDefaultType = Trim$(Mid$(strFltrCnt, posn, 3))
  175.     End If
  176. End Property
  177.  
  178. Public Property Let InitialFile(strIFile As String)
  179.     strInitialFile = strIFile
  180.  
  181. End Property
  182.  
  183. Public Property Let InitialDir(strIDir As String)
  184.     strInitialDir = strIDir
  185.  
  186. End Property
  187.  
  188. '   This routine initializes the string constants that are used by this class
  189. '
  190. Private Sub Class_Initialize()
  191.                         'define some initial conditions
  192.     strDialogTitle = "Browse For a File"
  193.     strInitialDir = ""
  194.     strInitialFile = ""
  195.     strNewTypes = ""
  196.                         'define the filter string and the look-up strings
  197.     strFilter = "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & _
  198.                 "Text Files (*.txt;*.prn;*.csv)" & vbNullChar & "*.txt;*.prn;*.csv" & vbNullChar & _
  199.                 "Word Documents (*.doc)" & vbNullChar & "*.doc" & vbNullChar & _
  200.                 "Word Templates (*.dot)" & vbNullChar & "*.dot" & vbNullChar & _
  201.                 "Excel Files (*.xls)" & vbNullChar & "*.xls" & vbNullChar & _
  202.                 "Databases (*.mdb)" & vbNullChar & "*.mdb" & vbNullChar & _
  203.                 "HTML Documents (*.html;*.htm)" & vbNullChar & "*.html;*.htm" & vbNullChar
  204.  
  205.     strFltrLst = "*.* *.txt *.prn *.csv *.doc *.dot *.xls *.mdb *.html"
  206.     strFltrCnt = "  1   2     2     2     3     4     5     6     7   "
  207.  
  208. End Sub
Mar 28 '07 #1
1 1963
Denburt
1,356 Recognized Expert Top Contributor
I am not sure why you want to use the API the DIR() function it is so much easier to use... I am sure I could google for the api but it is late I will check back in the AM.
Mar 30 '07 #2

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

Similar topics

5
6853
by: kevin | last post by:
Hi, Any help with this would be really appreciated! I'm trying to download a file from a remote server. The access permissions is okay but the problem I'm facing is that the file is getting...
12
1537
by: Ger | last post by:
My dialogue form (sometimes partly, sometimes as a whole) remains visible during a fairly long processing job. The dialogue asks the user to enter some data for the job to follow, and after OK,...
44
2102
by: sasan3 | last post by:
Please read below for my collective response to recent posts on this topic. First a repeat of my suggestion: "Anytime you feel you are in a position to answer a question, but don't feel like...
0
1467
by: Chad Dollins | last post by:
This is technically my first full scale VS project, so I may be way off base. I would like to develop an application that can import, export, combine, and edit distribution list from outlook. ...
3
9128
by: UltimateNickFury | last post by:
Hello, I am trying to display the "Printer Settings" dialogue in vb.net. I have found the code for performing this in VB6 but am wondering how this is done in vb.net. Thanks.
4
2377
by: developing | last post by:
Hi All, I have a browse button that the user can click to select a file. The button then fetches the file path. This is all working fine except my boss wants some add functionality. I need it to...
12
2161
by: Donn Ingle | last post by:
Hi, Okay, so I am in the mood to try this: Inform the user about what modules the app requires in a graphical dialogue that can vary depending on what the system already has installed. (It will...
1
3231
by: crazywu | last post by:
I have completed a script which opens various txt files within a folder path and does calculations on them, currently being set for example: path = "./files" is there a simple solution to grab...
3
3488
by: sierra7 | last post by:
Hi, I have a report that displays the correct data in Preview but displays #Name? when printed. (Access 2003) The field is unbound but the control source is read from a form =!. & " (Week " &...
0
7067
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
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
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
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.