Question Attachment field

mcclunyboy

Registered User.
Local time
Today, 09:41
Joined
Sep 8, 2009
Messages
292
Hi,

Using an attachment field - can we specify the location to search?

We have an Access 2007 DB and need to attach files from only 1 location - we hope to attach a copy of these files into the database effeciently.

I have a few sample DB's that use VB but I am hoping there is a quick and easy solution for this.
 
You can use the FileSystem objects to open dialogue boxes that allow a user to browse for a folder or file
ie
Application.FileDialog(msoFileDialogFolderPicker)
Application.FileDialog(msoFileDialogFilePicker)
Once a folder has been specified using the above, you can use
With Application.FileSearch
.NewSearch
.LookIn = folderPath
.SearchSubFolders = False

If .Execute > 0 Then
Set fs = CreateObject("Scripting.FileSystemObject")
For Each vaFileName In .FoundFiles
If vaFileName Like "*.csv" Then

This snippet of code will grab all .csv's from the folder held by the variable folderPath

Is the type of thing you mean?
David
 
the dirtiest solution I found was to open Access Options and change the "default database folder" - this allowed the attachments dialogue box to open where I wanted....this is a temporary work around.

the code is more along the ideal solution. I currently have the following code, borrowed from somewhere else, to select a file and load it into a text box. I am now going to physically move that file to a new backup directory and update the table (add a hyperlink column)...that's the plan..unless there is a better solution.

Code:
Private Sub Command9_Click()
'On Error GoTo Command9_Click
   
    Dim strFilter As String
    Dim lngFlags As Long
    Dim varFileName As Variant

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

    lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly

    varFileName = tsGetFileFromUser( _
    fOpenFile:=True, _
    strFilter:=strFilter, _
    rlngflags:=lngFlags, _
    strInitialDir:="c:\backup_dir\", _
    strDialogTitle:="Find File (Select The File And Click The Open Button)")

    If IsNull(varFileName) Or varFileName = "" Then
        Debug.Print "User pressed 'Cancel'."
        Beep
        MsgBox "File selection was canceled.", vbInformation
        Exit Sub
    Else
        txt_attachments = varFileName
        FileCopy
        'tbFile = varFileName
    End If
   

Exit_Command9_Click:
    Exit Sub
 

Users who are viewing this thread

Back
Top Bottom