Results 1 to 7 of 7
  1. #1
    zsmith is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2014
    Posts
    3

    HELP! Need to modify code to look in subfolders

    Here is the code for my Access 2003 database.

    -----------------------------------------------
    Option Compare Database
    Option Explicit


    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    MyStringForm = ""

    Dim MyFileName As String
    Dim MyFileExt As String
    Dim MyString, MyNumber
    Dim MyFile, MyFolder, SourceFile, DestinationFile


    MyFileName = Forms![Documents]![DocumentID]
    MyFileExt = Forms![Documents]![EntryValue]

    MyFolder = "//"serverip"/NWSDocuments/" & MyFileName & "." & MyFileExt
    MyFile = Dir(MyFolder, vbDirectory)
    If MyFile = "" Then


    MsgBox "File not found.", vbOKOnly + vbInformation, "No File"

    Exit Sub
    End If

    MyFile = "//"serverip"/NWSDocuments/" & MyFileName & "." & MyFileExt
    Close #1

    Open MyFile For Input As #1 ' Open file for input.

    Do While Not EOF(1) ' Loop until end of file.
    MyString = Input(1, #1) ' Get one character.
    Debug.Print MyString ' Print data to Debug window.
    If MyStringForm = "" Then
    MyStringForm = MyString
    Else
    MyStringForm = MyStringForm & MyString
    End If
    Loop

    Close #1 ' Close file.

    Me.Narrative = ConvertWord(MyStringForm)


    End Sub


    Private Sub Report_Activate()
    DoCmd.Maximize
    End Sub


    Private Sub Report_Close()
    DoCmd.Restore
    End Sub


    Function ConvertWord(RTFString As String)
    Dim tempstring As String, RTFlength As Long, RTFposition As Long, bPosition As Long

    RTFposition = InStr(1, RTFString, "\fs24")
    RTFlength = Len(RTFString)
    If RTFposition > 0 Then
    tempstring = Right(RTFString, RTFlength - RTFposition - 4)
    Else
    tempstring = RTFString
    End If

    RTFposition = InStr(1, tempstring, "\fs29")
    RTFlength = Len(tempstring)
    If RTFposition > 0 Then
    tempstring = Right(tempstring, RTFlength - RTFposition - 4)
    Else
    tempstring = tempstring
    End If

    bPosition = InStr(1, tempstring, "\par")
    Do While Not bPosition = 0
    Mid(tempstring, bPosition, 4) = " "
    bPosition = InStr(1, tempstring, "\par")
    Loop

    bPosition = InStr(1, tempstring, "\cf0")
    Do While Not bPosition = 0
    Mid(tempstring, bPosition, 4) = " "
    bPosition = InStr(1, tempstring, "\cf0")
    Loop

    bPosition = InStr(1, tempstring, "}")
    Do While Not bPosition = 0
    Mid(tempstring, bPosition, 1) = " "
    bPosition = InStr(1, tempstring, "}")
    Loop

    bPosition = InStr(1, tempstring, "\line")
    Do While Not bPosition = 0
    Mid(tempstring, bPosition, 5) = " "
    bPosition = InStr(1, tempstring, "\line")
    Loop

    ConvertWord = tempstring

    End Function
    --------------------------------------------

    I have bolded the problem code. This code is pointing to a folder on a server. When the database calls for a certain DocumentID, it searches this folder. Now, the program that created these logs creates subfolders based on the documentid and the database can no longer pull files. I want to do one of two things.

    Either:
    Recode this part to automatically look in all subfolders for a file

    OR


    Recode this to search the current folder and if it's no there then look in the subfolder based on the documentID.
    The subfolder structure is to 1. Create a subfolder based on the first 4 characters of the filename 2. Create a second subfolder based on the next two characters 3. deposit files

    EX.
    filename = xxxxyy22

    goes to
    \\xxxx\yy\xxxxyy22.doc

    Thank you all so much

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Here is example code to recursively list folders: http://www.allenbrowne.com/ser-59.html
    Instead of just listing folder, modify code to do a search in each folder.

    But if you know what the file path and name should be, then just specify them in the search http://allenbrowne.com/func-11.html

    What is the 'current folder' - where the database resides? Use CurrentProject.Path
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    zsmith is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2014
    Posts
    3
    I wanted to have it look in each folder, what mods do I need to make in the above code?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    I don't know your database and not really sure what it is you need to search for. What has ConvertWord function got to do with this issue?

    If they are applicable, suggest you make attempt following Allen's examples and when you encounter specific issue, post question.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    YaseenIskaf is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    14
    can we got an Attach small sample on this please . thank you all ?

  6. #6
    zsmith is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2014
    Posts
    3
    Maybe I'm not being clear. All I want to know is how to change that line to not "give up" after the file is not found in the \\serverip\nwsdocuments\ folder. I just want the app to point to that folder and always search within that one and all subfolders for the file it wants. That's it. I am asking because I am trying to fix it and don't know much about access. The guy that wrote it is long gone.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Allen Browne's procedure takes a starting folder path location as argument. It lists all folders and subfolders below that location, however deep. So your starting path is "\\serverip\nwsdocuments\"

    Just do a test with Allen's procedure without modification. Put the code in a general module and call it from the VBA Immediate Window:

    ?ListFiles("\\serverip\nwsdocuments\")

    If that works then look at modifying for your requirements.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to modify code to open report instead of form
    By kassem in forum Programming
    Replies: 4
    Last Post: 06-10-2014, 07:02 PM
  2. Import multiple xls from a few subfolders
    By artec in forum Import/Export Data
    Replies: 6
    Last Post: 03-31-2012, 09:23 AM
  3. SQL*Plus code in MsAccess, how to modify?
    By suverman in forum Queries
    Replies: 1
    Last Post: 05-20-2011, 07:01 AM
  4. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  5. Replies: 6
    Last Post: 09-30-2010, 11:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums