Complicated bug - Path not found - When passing arg value

duthiedon

Donner
Local time
Today, 17:28
Joined
Dec 27, 2007
Messages
60
Need some help badly! Have been struggling with trying to resolve this issue for awhile with various solutions. The code is a mix of someone else's and mine. Essentially the form is like a document library, based on the parameters in the form, it takes the original document that is selected by the user, then copies the file over to a central repository. When I don't pass a value over from another form using the following:

Me!AssociatedFeedback = Me.OpenArgs

Then everything works fine. Doesn't matter where I put this line of code (form open, after update, etc.) I get an MS Access error that says "Path Not Found" when you execute the "cmdSave" button.

Below is all the code for the form plus I have attached a screen shot of the form fields.

Any advice? Might be something simple that i've overlooked.

Code:
Option Compare Database
Option Explicit
Dim strFilePathFrom As String
Dim strFileFrom As String
Dim strFilePathTo As String
Dim strFileTo As String
Dim strFileDeskTop As String


Private Sub cmbDocumentType_AfterUpdate()

    Me!txtDocumentRef = Format(Me!txtSubmissionDate, "yyyymmdd") & Me!cmbDocumentType.Column(0) & _
    Me!txtVersion & Format(Me!txtDocumentID, "0000") & "." & Me!cmbDocExtension
    
End Sub

Private Sub cmdCloseForm_Click()
On Error GoTo Err_cmdCloseForm_Click

    DoCmd.Close

Exit_cmdCloseForm_Click:
    Exit Sub

Err_cmdCloseForm_Click:
    MsgBox Err.Description
    Resume Exit_cmdCloseForm_Click

End Sub

Private Sub cmdFileDeskTop_Click()
On Error GoTo Err_cmdFileDeskTop_Click
Dim strDirTo As String
Dim gfni As asl_accOfficeGetFileNameInfo
    ' File Select common dialog
    
    
    Dim fOpenMode As Boolean
   
    fOpenMode = False   ' false for save, true for open
    
    With gfni
        ' common dialog variables
        '.hwndOwner = Application.hWndAccessApp
        .hwndOwner = Me.hWnd
        .strDlgTitle = "Save File To"
        .strOpenTitle = "Save As"
        .strFile = Me!txtDocumentRef
        .strInitialDir = "C:\"
        .strFilter = "All Files(*.*)|Excel Files(.xls)|Rich Text Files(.rtf)|" & _
                     "Text Files(.txt)|Word FIles(.doc)|Zip Files(.zip)"
        .lngFilterIndex = 1
        .lngView = aslcGfniViewList
        .lngFlags = aslcGfniNoChangeDir Or aslcGfniInitializeView
        
    End With
            
    If aslOfficeGetFileName(gfni, fOpenMode) = aslcAccErrSuccess Then
        strFileDeskTop = Trim(gfni.strFile)
        strFileTo = aslGetFileName(Trim(gfni.strFile))
    End If

        'Me!txtDocumentDesktop = Trim(gfni.strFile) & "\" & Me!txtDocumentRef
        Me!txtDocumentDesktop = Trim(gfni.strFile)
        
'verify fields

    If IsNull(Me!cmbDocumentType) Or Me!cmbDocumentType = "" Then
  
        MsgBox "Please Select A Document Type.", vbOKOnly, "Documents"
        Me!cmbDocumentType.SetFocus
        Exit Sub
        
   ' ElseIf IsNull(Me!txtSubmissionDate) Or Me!txtSubmissionDate = "" Then
  
   '     MsgBox "Please Enter Submission Date.", vbOKOnly, "Documents"
   '     Me!txtSubmissionDate.SetFocus
   '     Exit Sub
    ElseIf IsNull(Me!txtVersion) Or Me!txtVersion = "" Then
  
        MsgBox "Please Enter Version.", vbOKOnly, "Documents"
        Me!txtVersion.SetFocus
        Exit Sub
        
    ElseIf IsNull(Me!cmbDocExtension) Or Me!cmbDocExtension = "" Then
  
        MsgBox "Please Document File Extension.", vbOKOnly, "Documents"
        Me!cmbDocExtension.SetFocus
        Exit Sub
        
   Else
        
        strFilePathFrom = Trim(Me!txtDocumentPathTo)
        strFileDeskTop = Trim(Me!txtDocumentDesktop)
        
        If Dir(GetDirectory(strFileDeskTop), vbDirectory) = "" Then
       
            MkDir GetDirectory(strFileDeskTop)
       
        End If
        
        FileCopy strFilePathFrom, strFileDeskTop
        MsgBox "File Has Been Saved To " & strFileDeskTop & ".", vbOKOnly, "Documents"
    
    End If
        
Exit_cmdFileDeskTop_Click:
    Exit Sub

Err_cmdFileDeskTop_Click:
    MsgBox Err.Description
    Resume Exit_cmdFileDeskTop_Click

End Sub

Private Sub cmdFileFrom_Click()
On Error GoTo Err_cmdFileFrom_Click

    ' File Select common dialog
    
    Dim gfni As asl_accOfficeGetFileNameInfo
    Dim fOpenMode As Boolean
    
   
    fOpenMode = False   ' false for save, true for open
    
    With gfni
        ' common dialog variables
        '.hwndOwner = Application.hWndAccessApp
        .hwndOwner = Me.hWnd
        .strDlgTitle = "Select File"
        .strOpenTitle = "Select"
        .strFile = strFileFrom
        .strInitialDir = "C:\"
        .strFilter = "All Files(*.*)|Excel Files(.xls)|Rich Text Files(.rtf)|" & _
                     "Text Files(.txt)|Word FIles(.doc)|Zip Files(.zip)"
        .lngFilterIndex = 1
        .lngView = aslcGfniViewList
        .lngFlags = aslcGfniNoChangeDir Or aslcGfniInitializeView
        
    End With
            
    If aslOfficeGetFileName(gfni, fOpenMode) = aslcAccErrSuccess Then
        strFilePathFrom = Trim(gfni.strFile)
        strFileFrom = aslGetFileName(Trim(gfni.strFile))
    End If
        Me!txtDocumentPathFrom = Trim(gfni.strFile)
        
Exit_cmdFileFrom_Click:
    Exit Sub

Err_cmdFileFrom_Click:
    MsgBox Err.Description
    Resume Exit_cmdFileFrom_Click

End Sub

Private Sub cmdFileTo_Click()
On Error GoTo Err_cmdFileTo_Click

    ' File Select common dialog
    
    Dim gfni As asl_accOfficeGetFileNameInfo
    Dim fOpenMode As Boolean
   
    fOpenMode = False   ' false for save, true for open
    
    With gfni
        ' common dialog variables
        '.hwndOwner = Application.hWndAccessApp
        .hwndOwner = Me.hWnd
        .strDlgTitle = "Save File To"
        .strOpenTitle = "Save As"
        .strFile = ""
        .strInitialDir = DLookup("[CodeDescription]", "tqryExport")
        .strFilter = "All Files(*.*)|Excel Files(.xls)|Rich Text Files(.rtf)|" & _
                     "Text Files(.txt)|Word FIles(.doc)|Zip Files(.zip)"
        .lngFilterIndex = 1
        .lngView = aslcGfniViewList
        .lngFlags = aslcGfniNoChangeDir Or aslcGfniInitializeView
        
    End With
            
    If aslOfficeGetFileName(gfni, fOpenMode) = aslcAccErrSuccess Then
        strFilePathTo = Trim(gfni.strFile)
        strFileTo = aslGetFileName(Trim(gfni.strFile))
    End If

        Me!txtDocumentPathTo = Trim(gfni.strFile) & "\" & Me!txtDocumentRef
        
Exit_cmdFileTo_Click:
    Exit Sub

Err_cmdFileTo_Click:
    MsgBox Err.Description
    Resume Exit_cmdFileTo_Click

End Sub

Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click


    Dim strDirTo As String
    Dim gfni As asl_accOfficeGetFileNameInfo
    
    If IsNull(Me!cmbDocumentType) Or Me!cmbDocumentType = "" Then
  
        MsgBox "Please Select A Document Type.", vbOKOnly, "Documents"
        Me!cmbDocumentType.SetFocus
        Exit Sub
        
   ' ElseIf IsNull(Me!txtSubmissionDate) Or Me!txtSubmissionDate = "" Then
  
   '     MsgBox "Please Enter Submission Date.", vbOKOnly, "Documents"
   '     Me!txtSubmissionDate.SetFocus
   '     Exit Sub
    ElseIf IsNull(Me!txtVersion) Or Me!txtVersion = "" Then
  
        MsgBox "Please Enter Version.", vbOKOnly, "Documents"
        Me!txtVersion.SetFocus
        Exit Sub
        
    ElseIf IsNull(Me!cmbDocExtension) Or Me!cmbDocExtension = "" Then
  
        MsgBox "Please Document File Extension.", vbOKOnly, "Documents"
        Me!cmbDocExtension.SetFocus
        Exit Sub
        
    ElseIf IsNull(Me!txtDocumentPathFrom) Or Me!txtDocumentPathFrom = "" Then
    
        MsgBox "Please Enter or Select The From Document Path.", vbOKOnly, "Documents"
        Me!txtDocumentPathFrom.SetFocus
        Exit Sub
        
   Else
   
        strDirTo = DLookup("[CodeDescription]", "tqryExport")
   
        Me!txtDocumentPathTo = DLookup("[CodeDescription]", "tqryExport") & "\" & Me!txtDocumentRef
        
        
        strFilePathFrom = Trim(Me!txtDocumentPathFrom)
        strFilePathTo = Trim(Me!txtDocumentPathTo)
        
        If Dir(strDirTo, vbDirectory) = "" Then
         
            MkDir strDirTo
            
        End If
        
        FileCopy strFilePathFrom, strFilePathTo
        
        'change the date on the file to local system date
        Dim diditwork As Boolean
        diditwork = SetFileDateTime("" & strFilePathTo & "", Now)
        
        'Need to get a handle to the new document and change its properties to READ ONLY
        SetAttr "" & strFilePathTo & "", vbReadOnly + vbArchive
        
        MsgBox "File Has Been Saved To " & strFilePathTo & ".", vbOKOnly, "Documents"
        
    'Me!AssociatedFeedback = Me.OpenArgs
    
    End If
Exit_cmdSave_Click:
    Exit Sub

Err_cmdSave_Click:
    MsgBox Err.Description
    Resume Exit_cmdSave_Click
End Sub

Private Sub CmdView_Click()
On Error GoTo Err_CmdView_Click

Dim ctl As CommandButton
Dim strAppName As String
Dim strObject As String

strAppName = Me!txtDocumentDisp

    Set ctl = Me!CmdView
    With ctl
        .Visible = True
        .HyperlinkAddress = strAppName
        .Hyperlink.Follow
    End With


Exit_CmdView_Click:
    Exit Sub
Err_CmdView_Click:
    MsgBox Err.Description
    Resume Exit_CmdView_Click
End Sub



Private Sub Form_AfterUpdate()

Me!AssociatedFeedback = Me.OpenArgs

End Sub

Private Sub Form_BeforeInsert(Cancel As Integer)

  '  Me!txtDocumentID = NextDocumentId()
    
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)

'Me!AssociatedFeedback = Me.OpenArgs

    If IsNull(Me!cmbDocumentType) Or Me!cmbDocumentType = "" Then
  
        MsgBox "Please Select A Document Type.", vbOKOnly, "Documents"
        Cancel = True
  
    ElseIf IsNull(Me!txtSubmissionDate) Or Me!txtSubmissionDate = "" Then
  
        MsgBox "Please Enter Submission Date.", vbOKOnly, "Documents"
        Cancel = True
  
    ElseIf IsNull(Me!txtVersion) Or Me!txtVersion = "" Then
  
        MsgBox "Please Enter Version.", vbOKOnly, "Documents"
        Cancel = True

    ElseIf IsNull(Me!cmbDocExtension) Or Me!cmbDocExtension = "" Then
  
        MsgBox "Please Document File Extension.", vbOKOnly, "Documents"
        Cancel = True

    Else

        Me!txtDocumentRef = Format(Me!txtSubmissionDate, "yyyymmdd") & Me!cmbDocumentType.Column(0) & _
        Me!txtVersion & Format(Me!txtDocumentID, "000") & "." & Me!cmbDocExtension
        Cancel = False
    End If
    
End Sub

Private Sub Form_Close()

   ' Forms!frmDocumentSearch!sfrmDocumentSearch.Requery
    
End Sub



Private Sub Form_Open(Cancel As Integer)

   ' Me!txtDocumentPathTo = DLookup("[CodeDescription]", "tqryExport") & "\" & Me!txtDocumentRef
 
End Sub

Private Sub cmbDocExtension_AfterUpdate()

    Me!txtDocumentRef = Format(Me!txtSubmissionDate, "yyyymmdd") & Me!cmbDocumentType.Column(0) & _
    Me!txtVersion & Format(Me!txtDocumentID, "0000") & "." & Me!cmbDocExtension

End Sub

Private Sub txtSubmissionDate_AfterUpdate()

    Me!txtDocumentRef = Format(Me!txtSubmissionDate, "yyyymmdd") & Me!cmbDocumentType.Column(0) & _
    Me!txtVersion & Format(Me!txtDocumentID, "0000") & "." & Me!cmbDocExtension

End Sub

Private Sub txtVersion_AfterUpdate()

    Me!txtDocumentRef = Format(Me!txtSubmissionDate, "yyyymmdd") & Me!cmbDocumentType.Column(0) & _
    Me!txtVersion & Format(Me!txtDocumentID, "0000") & "." & Me!cmbDocExtension

End Sub
 

Attachments

  • New Document Form.png
    New Document Form.png
    52.4 KB · Views: 136
Last edited:
Please wrap your code in the code wraps (see my sig)
 
You've pasted pages of code but not mentioned which line of code it errors on.
 
Hi vbaInet, that's because I don't know where the error is occurring. Just get the dialog box when the user executes the cmdSave function.
 
Thanks vbaInet, it doesn't like the following line of code in the cmdSave function:

FileCopy strFilePathFrom, strFilePathTo

The funny thing is, that it works when I don't use the "Me!AssociatedFeedback = Me.OpenArgs" in the code. Not sure the connection...

Any help is greatly appreciated!!
 
Either strFilePathFrom or strFilePathTo hasn't been set. You need to trace those two variables.
 
Both strFilePathFrom and strFilePathTo were defined as strings. The code works just fine until I add the line of code:

Me!AssociatedFeedback = Me.OpenArgs

I've experimented further but no luck. The code in the other form that opens this form where the args is located is as follows:

Code:
Private Sub cmdNewSubmission_Click()

On Error GoTo Err_cmdNewSubmission_Click

    Dim stDocName As String

    stDocName = "frmDocumentNew"
    
    DoCmd.OpenForm stDocName, , , , acFormAdd, OpenArgs:=Me![ID_VendorFeedback] & "|" & Me![VendorContact]
    Forms!frmDocumentNew.DataEntry = True

    
Exit_cmdNewSubmission_Click:
    Exit Sub

Err_cmdNewSubmission_Click:
    MsgBox Err.Description
    Resume Exit_cmdNewSubmission_Click


End Sub
 
Mmmm, I used the MsgBox Me.OpenArgs on both forms and they are not the same value.... mmmmmm
 

Users who are viewing this thread

Back
Top Bottom