Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileSearch Object Model, Help!! (Access 2k win 2k)

    Dear All

    I'm trying to use the FileSearch model to give me a list of files in a specific directory, the idea being to allow the user to select one specific file for further use. The code I'm using is below, it's a simplified version of the example in the Access Developers handbook by Getz et al. I realise there are a few sub and private procedures called in the examples they use that aren't well documented and I'm guessing I'm missing something critical from one of them, but what it is I can't work out.

    The last error mesage was about the object not being set, but set to what??

    Private Sub mlstFoundFiles_Enter()

    Dim File As Variant
    Dim mlstFoundFiles As MSForms.ListBox

    Set mlstFoundFiles = ??????????? (here because the last error message I got was that the object wasn't Set, but I've no idea what it should be set to???)


    With Application.FileSearch
    .NewSearch
    .LookIn = "C:"
    .FileName = "*.*"
    .SearchSubFolders = False
    .Execute

    For Each File In .FoundFiles
    mlstFoundFiles.AddItem File
    Next File

    End With
    End Sub

    So, I hurl myself on your mercy and ingenuity yet again.

    Thanks in advance.

    Ian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileSearch Object Model, Help!! (Access 2k win 2k)

    Sorry, nonsense reply posted initially, now deleted.

    The code you post is for a list box in a userform in Excel or Word. It doesn't apply to a list box in Access 2000, since it doesn't have an AddItem method. (In Access 2002, it has)

  3. #3
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSearch Object Model, Help!! (Access 2k win 2k)

    Hans

    Thank You, guess I'm following the examples too literally without digging deep enough into each section of code.

    As you said, once I'd removed the Dim statement the code worked. Yet another daft thing for me to over look I suppose, live and learn eh!!! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    I'm aiming to control the directory that will be searched so it doesn't have huge numbers of files in it, the C: was used for two reasons, I'm lazy and it's easy to type, also because I know that on my PC there aren't too many files in the root directory to list.

    Yet again you have saved my sanity <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Ian

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileSearch Object Model, Help!! (Access 2k win 2k)

    OK, let's try again. MSKB article ACC2000: How to Fill a List Box with File Names and Enable Printing of Files from a Form contains an example of how to fill a list box with a list of file names in Access 2000.

  5. #5
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSearch Object Model, Help!! (Access 2k win 2k)

    Hans

    Partly my fault, OK, mostly my error. The code is to be used with an Active X object, not an Access specific list box <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>. I omitted this information from the first post as an oversite, sorry.

    As I replied, your initial reply worked and explained exactly what I'd over looked, having checked through the examples I'd drawn the code from I had over complicated the issue in my own mind. I still have this belief that VBA is hard work, and so as not to disapoint myself tend to make it hard work by making silly mistakes. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Having said that the MSKB article does seem to have a few ideas as to how I can use ordinary list boxes for the same purpose.

    Thanks again for putting up with my questions.

    Ian

Posting Permissions

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