Consulting

Results 1 to 8 of 8

Thread: Combo Not working

  1. #1

    Combo Not working

    I attached an mdb file which has a combox box on a form
    that should list all text files in the directory which would then allow the user to select the required file. As you can see it is not working.
    Can somebody give me a hand


    Thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try
    Private Sub Form_Load()
    Dim MyPath As String, MyName As String
    MyPath = CurrentProject.Path & "\"    ' Set the path.
    MyName = Dir(MyPath, vbDirectory)    ' Retrieve the first entry.
    Do While MyName <> ""    ' Start the loop.
        If UCase(Right(MyName, 3)) = "TXT" Then
            Me.Text1.AddItem MyName
        End If
        MyName = Dir    ' Get next entry.
    Loop
    End Sub

    BTW, calling your combobox Text1 is a recipe for confusion. Something like cboMyFiles would be meaningful, and the prefix allows possible code handling of multiple combos, textboxes etc.
    Last edited by Aussiebear; 04-27-2023 at 04:21 AM. Reason: Adjusted the code tags
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Thanks for your rapid reply MDMack

    So far so good. Copied your code over and now the combo
    box works.
    The value (filename) in Text1 however is not passed over to the command button as in Call GetFile(Me.Text1)

    Regards
    Jmentor

  4. #4
    MDMack

    Forgot to mention that an error popped up telling me
    to change the combo box to Value List

    Jmentor

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Apologies. Forgot about the Value List warning.
    You didn't show your GetFile routine, so I'm not sure what you're doing with the found file. To open it, something like
    Sub getfile(MyFile As String)
    Application.FollowHyperlink CurrentProject.path & "\" & MyFile
    End Sub
    Last edited by Aussiebear; 04-27-2023 at 04:21 AM. Reason: Adjusted the code tags
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    MDMack

    Aplogies
    Could have sworn I attached the mdb. Obviously forgot to do so.

    The code on the button is this.

    Private Sub Command1_Click()
      If Len(Me.Text1) Then
        Call GetFile(Me.Text1)
      End If
    End Sub

    In this lightof what you have supplied what do I need to change on the button to pick up the selected file

    Thanks
    Jmentor
    Last edited by Aussiebear; 04-27-2023 at 04:22 AM. Reason: Adjusted the code tags

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    GetFile is not a built in function. You need to write some code to carry out whatever actions you require on the text file. My example opens the file.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    Get File is a function I have in another database

Posting Permissions

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