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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » FileSearch Object Model, Help!! (Access 2k win 2k)

    Author
    Topic
    #391568

    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

    Viewing 1 reply thread
    Author
    Replies
    • #699896

      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)

      • #699900

        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!!! smile

        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 clapping cheers

        Ian

    • #699902

      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.

      • #699908

        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 sorry. 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. smile

        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

    Viewing 1 reply thread
    Reply To: FileSearch Object Model, Help!! (Access 2k win 2k)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: