Results 1 to 9 of 9

Thread: How to populate listbox with data from access and text file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow How to populate listbox with data from access and text file

    Hi all. Could any one show me how i can populate a listbox with data from ms access db and text file.Thanks

  2. #2
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Red face Re: How to populate listbox with data from access and text file

    Try this:

    VB Code:
    1. Private Sub commandLoad_click()
    2. Dim sText As String
    3.     Dim X As Integer
    4.     X = FreeFile
    5.     On Error Resume Next
    6.     Open App.Path & "/textfilename.txt" For Input As #X
    7.     While Not EOF(X)
    8.         Input #X, sText$
    9.             List1.AddItem sText$ ' adds in to listbox1
    10.             DoEvents
    11.     Wend
    12.     Close #X
    13.  
    14. End Sub
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to populate listbox with data from access and text file

    Thank u for u reply. It does not work. all i see the scroller moving for ever and no data is shown in listbox!!

  4. #4
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: How to populate listbox with data from access and text file

    It happens when the file does not contain any data. The should be a data in a etxt file like this:
    254
    ngng
    fbhfbn
    fbbf
    fb
    b356.

    Try It.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to populate listbox with data from access and text file

    well my file has data line by line and i tried u data too and it did not work!! Do i need any refrences or components or change in listbox property? i place the text file in c:\ do i need to put c:\ in the path too ?

  6. #6
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: How to populate listbox with data from access and text file

    How many lines are in your text file?

    Can you post your file?

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to populate listbox with data from access and text file

    Quote Originally Posted by lintz
    How many lines are in your text file?

    Can you post your file?
    oh got it working i had to put the text file in same folder as vb project is . Thanks

  8. #8
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: How to populate listbox with data from access and text file

    that's what App.Path means

  9. #9
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: How to populate listbox with data from access and text file

    Yes that is what u had to odo. Please rate my post.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

Posting Permissions

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



Click Here to Expand Forum to Full Width