Linking files to a database from a specific folder

Psiren17

Registered User.
Local time
Today, 03:57
Joined
Nov 18, 2005
Messages
31
I use the following code (got from this forum somewhere a while back) to open a "browse" box which enables my user to link a file to the database. it works from an "add" button which then places the string for the file into a field and turns it into a hyperlink using another bit of code.

I now need to change it so that it will only allow my users to choose a file from a specific folder. This is because we have some uninformed users who attach a file which is on their PC desktop and then wonder why no one else can open it!

Can anyone help please?


Private Sub add1_Click()

On Error GoTo add1_Err
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant

strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
& vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"

lngFlags = tscFNPathMustExist Or tscFNFileMustExist _
Or tscFNHideReadOnly

varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngFlags, _
strDialogTitle:="Please choose a file...")

If IsNull(varFileName) Then
Else
Me![Attach drawing:] = varFileName
End If

add1_End:
On Error GoTo 0
Exit Sub

add1_Err:
Beep
MsgBox Err.Description, , "Error: " & Err.Number _
& " in file"
Resume add1_End


End Sub
 
Can anyone help please?
Can you please use CODE tags when you post code??

Code:
Private Sub add1_Click()

On Error GoTo add1_Err
   Dim strFilter As String
   Dim lngFlags As Long
   Dim varFileName As Variant

   strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
    & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
    
   lngFlags = tscFNPathMustExist Or tscFNFileMustExist _
    Or tscFNHideReadOnly
   
   varFileName = tsGetFileFromUser( _
   fOpenFile:=True, _
   strFilter:=strFilter, _
   rlngflags:=lngFlags, _
   strDialogTitle:="Please choose a file...")
   
   If IsNull(varFileName) Then
    Else
      Me![Attach drawing:] = varFileName
   End If

add1_End:
   On Error GoTo 0
   Exit Sub

add1_Err:
   Beep
   MsgBox Err.Description, , "Error: " & Err.Number _
    & " in file"
   Resume add1_End


End Sub
Your varFileName contains the full path for the Drawing you are trying to attach.
How about a simple check to see if the first character is a local drive, or a protected drive?
Code:
if left (varFileName,1) = "C" then 
    msgbox "Bad drive"
    exit sub
endif
Simularly you can check for a full path if you like... Using i.e. Left(,10) = "C:\Windows"

Good luck !
 
Thanks but that might take a while as we have a lot of places on our servers where i wouldnt want them to put the files due to permissions etc. Is there no easy way to specify a particular folder the file must come from?
 
The browse window (as far as I know) allows the user to browse to any spot anywhere the user can go... No way to limit that...

If you have many places, maybe you can make a table that contains these places, which you can then check against...
Maybe an exact folder doesnt matter (that much), but the drive does... I mean the C D E and H, first 3 local drives and H beeing my personal (but networked) drive that no one can touch.
Just preventing those 4 drives from beeing used will (probably) elimate 95% of all problems.
 
Sadly the exact folder does matter - we have a slightly odd system where we have one big drive with lots of secure folders. If someone attaches something thats in a secure folder no one else would be able to open it which kind of defeats the object!

Thanks anyway!
 
Maybe, just maybe... You can use API calls to retrieve the protections/securitys from the folder given.

I have never tried to do this... but did do a quick google for you...
http://support.microsoft.com/kb/295004
Looks promissing, but I cannot say anything as to the feasabiltiy of this.
 
Can you please use CODE tags when you post code??

Code:
Private Sub add1_Click()

On Error GoTo add1_Err
   Dim strFilter As String
   Dim lngFlags As Long
   Dim varFileName As Variant

   strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
    & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
    
   lngFlags = tscFNPathMustExist Or tscFNFileMustExist _
    Or tscFNHideReadOnly
   
   varFileName = tsGetFileFromUser( _
   fOpenFile:=True, _
   strFilter:=strFilter, _
   rlngflags:=lngFlags, _
   strDialogTitle:="Please choose a file...")
   
   If IsNull(varFileName) Then
    Else
      Me![Attach drawing:] = varFileName
   End If

add1_End:
   On Error GoTo 0
   Exit Sub

add1_Err:
   Beep
   MsgBox Err.Description, , "Error: " & Err.Number _
    & " in file"
   Resume add1_End


End Sub
Your varFileName contains the full path for the Drawing you are trying to attach.
How about a simple check to see if the first character is a local drive, or a protected drive?
Code:
if left (varFileName,1) = "C" then 
    msgbox "Bad drive"
    exit sub
endif
Simularly you can check for a full path if you like... Using i.e. Left(,10) = "C:\Windows"

Good luck !


try this...i modified the c drive check above and coded in the entire UNC name of your shared folder. that way if the file name does not start with the folder you want it will not save the file


Code:
If Left(varFileName, 25) <> "\\abc\workgroup\serv1\rdt" Then
    MsgBox "Please attach a file from the shared drive"
    Exit Sub
 
Hi,

I don't actually have any help on this, but the general principle seems to be exactly what I am looking for. Can you recall where you originally got the code from or would someone be able to explain it as the lazy method of just cutting and pasting doesn't work. Basically what I am after is for the user to be able to brouse for the fime and then to be able to check that the file is in the current directory, I believe I can do the latter but have until now been stumped on the former
 

Users who are viewing this thread

Back
Top Bottom