By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Limiting Browse Button

100+
P: 110
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 be so that the user can only access Z: and Y: and not W: or X:

Any help is highly appreciated. Thanks a lot

The current code I am using is is posted below. (this works just fine)

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


nico5038
Expert 2.5K+
P: 3,072
There's no sense in this requirement, as when a user has access to folders, he can always copy/paste files from a "resticted" drive to an "allowed" drive.

When your boss wants to hide those drives for certain users, he'd better ask the systemmanager to create a special userprofile for users only showing Z: Y: and no W: and X:

Nic;o)
Mar 3 '07 #2

P: 39
Is there a reason you can't just use standard windows NTFS permissions and restrict access to the drives, rather than trying to hide them?

I can certainly help you with that.
Mar 3 '07 #3

100+
P: 110
Is there a reason you can't just use standard windows NTFS permissions and restrict access to the drives, rather than trying to hide them?

I can certainly help you with that.
Yes, that is true. but since this will be a access basd application running on a server, we really dont want to have to go configure each system seperately...unless of course there is no other way
Mar 5 '07 #4

nico5038
Expert 2.5K+
P: 3,072
There's no need to install different versions. Just try with a user that's not having Access to W: and Y: to see.

Nic;o)
Mar 5 '07 #5

Post your reply

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