Consulting

Results 1 to 2 of 2

Thread: Error 91 due to incorrect With Statement or Object Not Defined

  1. #1
    VBAX Newbie
    Joined
    Jul 2019
    Posts
    1
    Location

    Error 91 due to incorrect With Statement or Object Not Defined

    I want to post first and foremost, I am not a programmer. Our company recently updated our microsoft access database from 2013 to 2016. We were told they will no longer support it. I keep getting an error on the following code since the update "Error 91 due to incorrect With Statement or Object Not Defined". I completed some research on-line and found out Access 2016 does not use Application.FileSearch, but I do not know what to use as the new replacement coding. The End With statement may not be closing right. Everything else appears to work in the database except this VBA section

    This code was written to merge a word document originally from Microsoft Access. Any Assistance is much appreciated to correct this code.

    Dim finddoc As Stringfinddoc = Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 3, 5) & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 9, 3) & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 13, 2) & " " & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipARMS#], 6, 3) & ".doc"
    Dim CR
    CR = Chr(13)
    On Error GoTo dfLettersPInspError
    With Application.FileSearch
        .NewSearch
        .LookIn = pubPermitDocFolder  'a constant in GenMods module
        .SearchSubFolders = False
        .FileName = finddoc
        .MatchTextExactly = True
        .FileType = msoFileTypeWordDocuments
        If .Execute() > 0 Then
            pubCopyPermitDoc = finddoc
        Else
            pubCopyPermitDoc = Null
            MsgBox ("An electronic version of the permit conditions is not available." & CR & "Please see your supervisor about creating one, or using an" & CR & "existing inspection format.")
            Exit Sub
        End If
    End With
    DoTheMerge:
    Call dmerge(WordDoc, MergeQuery, SaveFolder)
    Exit Sub
    dfLettersPInspError:
    MsgBox ("error # " & Err.Number & Err.Description)
    Resume Next
    End Sub

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,046
    Location
    First of all this is most unusual
    Dim finddoc As Stringfinddoc = Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 3, 5) & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 9, 3) & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 13, 2) & " " & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipARMS#], 6, 3) & ".doc"

    It would normally be written as

    Dim finddoc As String
    finddoc = Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 3, 5) & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 9, 3) & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipPermNo], 13, 2) & " " & Mid(Forms![fFacInsp01]![fFacInspSetup01].Form![ipARMS#], 6, 3) & ".doc"

    If after making the change the problem persists there are other methods including File Scripting Object (FSO) and the old fashioned DIR.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •