right click menu that point to accdb or accde

Cotik

New member
Local time
Today, 15:28
Joined
Dec 23, 2022
Messages
4
I wondered if is there a way starting from the windows file system, to open a accdb or accde application with the right click of a a specific file generated into a specific folder from a third part software, while getting the path's file in order to work with the string name of file and its parent folder to move and rename them at the end of some processes
 
Last edited:
you can use a macro recorder program or a vbscript?
 
I don't know, i'm little poor with code except for basics vba, the file whose path i would get is generated toghether with its parent folder. I would like users, after searched and got the file in usual way into the folder system, can open an accde application (with right click menu or some differents ways) starting from the windows file system and get its complete path for subsequent operations.
 
Last edited:
This is code that you need to write OUTSIDE of Access and VBA. If the file you want to click on has a special extension, say .special, then you could add a file association to windows to associate .special with some program you write and compile.

So, somehow, you are downloading access databases into a folder and you want to rename the files and move them to a different folder? Do you actually want to open the files and do anything? This is a really unusual request for something involving .accdb and .accde files.

Please tell us more about the whole situation.
 
I'm sorry, think i was not enough clear, i try to explain:
in dental manifactures process, there's a cad software whereby users, projects and design a sort of prototypes (every tooth is different and need to be machined as single project). At the end of design procedures, this software generates a model file (destinated to be machined in a subsequent cam procedure) and show it into fhe folder system in order to allow users to send it via lan.
This file is named approximately this way: yyyymmdd-[IdCustomer]-[ID Progressive of the day] and it's generated (together with some other files) inside a folder with the same name, in a specific path.
My goal is to copy this folder string into a db table, allow user to add some data in order to manage it in a better way into the workflow. Here's the reason why i need to capture the file string name (or folder) at the moment that the software shows it into the fileSystem, and open ( or get active) my db application at the same time.
Create an association with extenction file is not probably the best solution in this case, this kind of files had associations with proper viewer that i prefer not to modify.
Maybe a solution could be a macro recorded or something like this. Regarding vbScript, i don't know much around its possibility outside access, because of course, the solution i'm searching for, could be only outside Access.
Thank you for any suggestion
 
Last edited:
Think you would need to have your CAD software to do that. Alternatively this link may be of help
 
OK, the new explanation is far more normal a request. Here's a picture of a form I use in an application that imports (actually just stores the location) scanned documents that were downloaded from an FTP server. The mail goes to a third party that handles opening the mail and scanning the documents as well as naming the scanned document images to our standards so we can file them correctly. Similar to your situation. The form shows a source folder and a destination folder. Both have defaults but can be overridden if necessary. The other stuff is irrelevant to your needs. It is used to send an acknowledgement email or letter to the person who mailed in the scanned documents to confirm their receipt.
DEAScannedInput.JPG

The code used to handle the process uses FSO (File System Object) which will require that you add a reference to the Microsoft Office 11.0 Object Library - or whatever version number you have currently installed. I cut out a lot of the code you won't need but perhaps not all of it. I was trying to not break the code that is left. Obviously you can't just use it as is but it shows you how to process a folder filled with files and do something with each of them and ends with deleting the files from the download folder when the process ends.

Notice that the code separates the file name into an array so that it can be parsed. If you need to control which folder your files get moved to, you have the same issue to deal with. If all the files end up in the same folder, then you probably don't need to parse the file name.

There are three procedures. The first is the click event of the "Import Documents" button. The second is the code later called by that button click. The third is the code called by the two "Browse" buttons that let you also use FSO to use the file dialog to pick the name of a folder.

Some of the code is in the next message since it is too long for this post.
Code:
Private Sub cmdImport_Click()

    Dim ErrReturn As Long
    
On Error GoTo Err_Proc
    If Me.txtSourceFolderName & "" = "" Then
        MsgBox "Please enter a source folder name.", vbOKOnly + vbCritical
        Exit Sub
    End If
    If Me.txtTargetFolderName & "" = "" Then
        MsgBox "Please enter a target folder name.", vbOKOnly + vbCritical
        Exit Sub
    End If
    If Me.cboDocID & "" = "" Then
        If IsNull(DLookup("ACKDocReceipt", "tblAuditParms", "AuditParmsID = " & Forms!frmLogin!cboAuditParmsID)) Then
        Else
            MsgBox "Please select an acknowledgement letter.", vbOKOnly + vbCritical
            Exit Sub
        End If
    End If
    
    gHoldMemberDateTime = Now()
    Me.txtDocCount = Null
    Me.txtErrCount = Null
    Me.txtErrFolder = Null
    Me.txtImportedCount = Null
    Me.txtClientIDErr = Null
    Me.txtDupsErr = Null
    Me.txtEmpIDErr = Null
    Me.txtAuditAbbrErr = Null
    Me.txtPrinted = Null
    Me.txtDocCount = LogScannedDocs(Me.txtSourceFolderName, Me.txtTargetFolderName, Me)
    Me.txtImportedCount = Me.txtDocCount - Me.txtErrCount
    
Exit_Proc:
    Exit Sub
Err_Proc:
    Select Case Err.Number
        Case 2501
            Resume Exit_Proc
        Case 3021
            Resume Next
'        Case 58     'file already exists
'            Resume Next
'        Case 53
'            Resume Next
        Case 91
            Resume Next
        Case 3059
            MsgBox "Import cancelled.", vbOKOnly + vbInformation
            Resume Exit_Proc
        Case 3265
            ErrReturn = 3265
            Resume Next
        Case Else
            MsgBox Err.Number & "--" & Err.Description, vbCritical
            Resume Exit_Proc
    End Select
End Sub
 
Code:
Public Function LogScannedDocs(SourceFolderPath As String, TargetFolderPath, frm As Form) As Long
'Files are downloaded manually from the FTP site to a folder on the server (this will be automated later)
'Validate file names
'Copy downloaded files to appropriate audit folder or to "not copied" folder if an error is found
'Add record to reference docs table to link subscriber record to actual document
'Delete all files from the common download folder

    Dim db          As DAO.Database
    Dim rs          As DAO.Recordset
    Dim td          As DAO.TableDef
    Dim qd          As DAO.QueryDef

    Dim fs          As Scripting.FileSystemObject
    Dim folder      As Scripting.folder
    Dim file        As Scripting.file
    Dim filefolder
    Dim TextArray() As String
    Dim ErrCounter  As Long
    Dim ErrFolderName   As String
    Dim NewFolderName   As Variant
    Dim FromFileName    As String
    Dim strDocType      As String
    Dim iDupFileName As Integer
    Dim iPrinted As Integer
    Dim sReturnEmailBody As Variant
    Dim sPathName As Variant
    Dim SendEmailACK    As Boolean
    Dim strWhere        As String
    Dim sClientID       As String   'TPA identifier code
    Dim sCoAbbr         As String   'Audit identifier code
    Dim sEmpID          As String   'EmpID or EmpNum  '' documents all use EmpNum so doc name should also but some old docs will have EmpID so code will check both
    
On Error GoTo Err_Proc
    Set db = CurrentDb()
    
    iWrongClientID = 0
    iWrongEmpID = 0
    iWrongAuditAbbr = 0
    iDupFileName = 0
    iPrinted = 0
    sPathName = ""
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set folder = fs.GetFolder(SourceFolderPath)
    Set filefolder = folder.Files
    
    'recordset to log acknowledgement emails sent
    Set tdLtr = db.TableDefs("tblLtrSent")
    Set rsLtr = tdLtr.OpenRecordset(dbOpenDynaset, dbSeeChanges)
    
    ' Open recordset which will be used to add rows
    Set td = db.TableDefs!tblRefDocs
    Set rs = td.OpenRecordset(dbOpenDynaset, dbSeeChanges)
    ErrFolderName = SourceFolderPath & "\Errors"

    ' create "error" folder  if necessary
    If fs.FolderExists(ErrFolderName) Then
    Else
        fs.CreateFolder (ErrFolderName)
    End If
    
    'clear print log
    DoCmd.RunMacro "mWarningsOff"
    DoCmd.RunSQL ("Delete * From tblMissingEmail;")
    DoCmd.RunMacro "mWarningsOn"

    ErrCounter = 0
    FileCounter = 0

    For Each file In filefolder
        FileCounter = FileCounter + 1       
        TextArray = Split(file.Name, "-")   'separate parts of file name
        sPathName = TextArray(1)    'save for later use in err_proc
        'verify that ClientID is valid
        sClientID = TextArray(0)
        sCoAbbr = TextArray(1)
        sEmpID = TextArray(2)
        
        If sClientID <> Forms!frmLogin!txtClientID Then
            iWrongClientID = iWrongClientID + 1
            GoSub LogError
            GoTo ResumeAfterError
        End If
                    
        'add to reference docs table
            rs.AddNew
                rs!EmpID = rsMember!EmpID
                rs!DocType = strDocType
                rs!FullDocName = file.Name
                rs!Reviewed = 0
                rs!UpdatedBy = Forms!frmLogin!txtNetworkID
                rs!UpdatedDT = Now()
                rs!LoggedDate = Now()
            rs.Update
            
            'error 3146 resumes after rs.update so we have to avoid getting a second error
            If sCoAbbr & "" = "" Then
            Else
                NewFolderName = DLookup("ScannedDocPath", "tblAuditParms", "CoAbbr = '" & sCoAbbr & "'")
                '''''' can be removed because folder should already exist
                'create folder for coabbr if necessary
                If fs.FolderExists(NewFolderName) Then
                Else
                    fs.CreateFolder (NewFolderName)
                End If
                
                FromFileName = SourceFolderPath & "\" & file.Name
                If FromFileName = NewFolderName & "\" & file.Name Then 'file already added to error folder
  '                  Debug.Print "File already exists: " & FromFileName
                Else
                    fs.CopyFile Source:=FromFileName, Destination:=NewFolderName & "\"
                End If
            End If           

ResumeAfterError:   ' resume point for errors to let process continue
    Next
    
    On Error GoTo Err_Proc
    
    LogScannedDocs = FileCounter
    frm.txtErrCount = ErrCounter
    If ErrCounter > 0 Then
        frm.txtErrFolder = ErrFolderName
    End If
    
    Set rs = Nothing
    Set rsMember = Nothing
    
    On Error Resume Next
    Kill SourceFolderPath & "\*.*"      '''''Delete all files from Source folder
    On Error GoTo 0

Exit_Proc:
    frm.txtClientIDErr = iWrongClientID
    frm.txtDupsErr = iDupFileName
    Exit Function

LogError:
    ErrCounter = ErrCounter + 1
'    Debug.Print "error 3146 ---" & file.Name
    FromFileName = SourceFolderPath & "\" & file.Name
    fs.CopyFile Source:=FromFileName, Destination:=ErrFolderName & "\"
    Return
Err_Proc:
    Select Case Err.Number
        Case 58     ' file already exists
            Resume Next
        Case 53     ' File not found
            Debug.Print "error 53 ---" & file.Name
            Resume Next
        Case 76     ' Path not found
        
            'add logic to determine if any documents have been processed and continue or exit depending.
            If sPathName & "" = "" Then
                MsgBox "The destination folder may be incorrect. The following folder was not found - " & vbCrLf & TargetFolderPath, vbOKOnly + vbCritical
                Resume Exit_Proc
            Else
                MsgBox "The scanned path may be invalid for " & sPathName & ". The following folder was not found - " & vbCrLf & NewFolderName, vbOKOnly + vbCritical
                Resume Exit_Proc
            End If
        Case 3022   ' Duplicate file name
            iDupFileName = iDupFileName + 1
            GoSub LogError
            Resume ResumeAfterError
        Case 3146   'Could not save; currently locked by another user.
            GoSub LogError
            Resume ResumeAfterError
        Case 2465   'get this error when proc run from ack email because form doesn't have date fields
            Resume Next
        Case Else
            MsgBox Err.Number & "--" & Err.Description, vbCritical
            Resume Exit_Proc
            Resume
    End Select
End Function





Public Function fChooseDirectory()

    'Declare a variable as a FileDialog object.
    Dim fd As FileDialog

    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is a String that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.
                
                'Only one item will be returned since the file dialog is a folder picker
                'MsgBox "The path is: " & vrtSelectedItem
                fChooseDirectory = vrtSelectedItem
                Exit Function
            Next vrtSelectedItem
        'The user pressed Cancel.
        Else
        End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing
    fChooseDirectory = "Error - nothing chosen"
End Function
 
OK, the new explanation is far more normal a request. Here's a picture of a form I use in an application that imports (actually just stores the location) scanned documents that were downloaded from an FTP server. The mail goes to a third party that handles opening the mail and scanning the documents as well as naming the scanned document images to our standards so we can file them correctly. Similar to your situation. The form shows a source folder and a destination folder. Both have defaults but can be overridden if necessary. The other stuff is irrelevant to your needs. It is used to send an acknowledgement email or letter to the person who mailed in the scanned documents to confirm their receipt.
Thank you Pat, my project actually use the same your way for what concern the fso method that i used even in this project to parse the cad model's output directory in order to convert the strings name of the stored files and folders to our new current standard. What i really wanted to focused, for true, was a sort of shortcut outside my db application, that allow users to get start my db at the moment the cad sw shows the new folder created, into the windows folder manager, carrying along the folder's path just stored in. In this way, users don't need to use the file dialog to get the same folder they had just stored.
 
That is not something you want Access to do although it can. Access would have to be open all the time and it would need to use a hidden form with a timer to keep checking that folder. Someone else may post a better solution.

If Access isn't open, it can't start the process. I would look into what you can do with a script.
 

Users who are viewing this thread

Back
Top Bottom