Results 1 to 6 of 6

Thread: VBA DataGrid User Form

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    Is the data coming from an Excel range?

    You can use a Listbox or ComboBox with multiple columns. You can add each item individually or use RowSource or use List for addition by an array.

    I had trouble using the example in the help for the flexgrid control. I used the more simple example. Change the path to the NWind.mdb to test. We use something similar to query Excel data.
    'http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial3/index.html
    'Requires 2 controls from the toolbox: MSHFlexGrid and ADOdc
    Private Sub UserForm_Initialize()
     ' Create a ConnectionString.
    Dim strCn As String
    'strCn = "Provider=MSDataShape.1;Data Source=e:\excel\ado\Nwind.mdb;" & _
    "Connect Timeout=15;Data Provider=MSDASQL"
    strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\excel\ado\Nwind.mdb"
    
    
    ' Create a Shape command.
    Dim strSh As String
    'strSh = "SHAPE {SELECT * FROM `Customers`}  AS Customers " & _
    "APPEND ({SELECT * FROM `Orders`}  AS Orders RELATE " & _
    "CustomerID TO CustomerID) AS Orders"
    strSh = "SELECT * FROM Orders"
    
    ' Assign the ConnectionString to an ADO Data Control's
    ' ConnectionString property, and the Shape command to the
    ' control's RecordSource property.
    With Adodc1
       .ConnectionString = strCn
       .RecordSource = strSh
    End With
    ' Set the HflexGrid control's DataSource property to the
    ' ADO Data control.
    Set MSHFlexGrid1.DataSource = Adodc1
    
    End Sub
    Of course the Spreadsheet control is easy to use.
    http://www.mrexcel.com/forum/showthread.php?t=74529
    If you go this route, this link shows some other tips. http://excelkb.com/article.aspx?id=10190
    Last edited by SamT; 12-12-2014 at 01:37 PM. Reason: Edit [vba] to [code]

Posting Permissions

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