dcsimg
Results 1 to 6 of 6

Thread: load database name into listview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2015
    Posts
    20

    load database name into listview

    Hello Folks

    I'm Searching A Code Helping Me To Load The Name of Data Base's In app.path To My Listview So That I Can Click On The Name Of Desired Database From Listview1 And Display It In Listview 2



  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,843

    Re: load database name into listview

    Sounds pretty straightforward to me. However, a few more details if you please:

    What kind of databases are we talking about? *.MDB databases? *.ACCDB databases? Some kind of SQL Server databases?

    And also, what technology will you be using to open/read these databases? DAO? ADO? Something else?

    If you answer those questions, I'm sure people can provide more directed guidance.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2015
    Posts
    20

    Re: load database name into listview

    Quote Originally Posted by Elroy View Post
    Sounds pretty straightforward to me. However, a few more details if you please:

    What kind of databases are we talking about? *.MDB databases? *.ACCDB databases? Some kind of SQL Server databases?

    And also, what technology will you be using to open/read these databases? DAO? ADO? Something else?

    If you answer those questions, I'm sure people can provide more directed guidance.

    Good Luck,
    Elroy
    .MDB databases

    ADO

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,572

    Re: load database name into listview

    Why a list view?
    File list would be very easy, simply set the path and the pattern and it will add them automatically.
    Of course adding them to a list view is simple as well but unless you want to display multiple columns of info related to the db file not sure it makes sense to use a listview.

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,843

    Re: load database name into listview

    I used the ListView with "Microsoft Common Controls 6.0" but I believe this should work with 5.0 as well.

    I just threw a ListView and a CommandButton on a form, and then wrote the following code:

    Code:
    
    Option Explicit
    '
    
    Private Sub Form_Load()
        ListView1.View = lvwReport
        ListView1.ColumnHeaders.Add
        ListView1.HideColumnHeaders = True
    End Sub
    
    Private Sub Command1_Click()
        LoadListViewWithFiles GatherMdbFiles()
    End Sub
    
    Private Sub LoadListViewWithFiles(coll As Collection)
        Dim v As Variant
        Dim Item As ListItem
        '
        ListView1.ListItems.Clear
        For Each v In coll
            Set Item = ListView1.ListItems.Add(, , v)
        Next
    End Sub
    
    Private Function GatherMdbFiles() As Collection
        Dim sFile As String
        '
        Set GatherMdbFiles = New Collection
        sFile = Dir$(App.Path & "\*.mdb")
        Do While Len(sFile)
            GatherMdbFiles.Add sFile, sFile
            sFile = Dir$
        Loop
    End Function
    
    Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
        Dim sFileSpec As String
        '
        sFileSpec = App.Path & "\" & Item.Text
        Debug.Print sFileSpec
    End Sub
    
    

    With that, hopefully, you know how to open and use your database with the ADO.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2015
    Posts
    20

    Re: load database name into listview

    Quote Originally Posted by Elroy View Post
    I used the ListView with "Microsoft Common Controls 6.0" but I believe this should work with 5.0 as well.

    I just threw a ListView and a CommandButton on a form, and then wrote the following code:

    Code:
    
    Option Explicit
    '
    
    Private Sub Form_Load()
        ListView1.View = lvwReport
        ListView1.ColumnHeaders.Add
        ListView1.HideColumnHeaders = True
    End Sub
    
    Private Sub Command1_Click()
        LoadListViewWithFiles GatherMdbFiles()
    End Sub
    
    Private Sub LoadListViewWithFiles(coll As Collection)
        Dim v As Variant
        Dim Item As ListItem
        '
        ListView1.ListItems.Clear
        For Each v In coll
            Set Item = ListView1.ListItems.Add(, , v)
        Next
    End Sub
    
    Private Function GatherMdbFiles() As Collection
        Dim sFile As String
        '
        Set GatherMdbFiles = New Collection
        sFile = Dir$(App.Path & "\*.mdb")
        Do While Len(sFile)
            GatherMdbFiles.Add sFile, sFile
            sFile = Dir$
        Loop
    End Function
    
    Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
        Dim sFileSpec As String
        '
        sFileSpec = App.Path & "\" & Item.Text
        Debug.Print sFileSpec
    End Sub
    
    

    With that, hopefully, you know how to open and use your database with the ADO.

    Good Luck,
    Elroy
    Helped Me Alot
    Thank You

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width