Results 1 to 6 of 6

Thread: [RESOLVED] soo confused.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Resolved [RESOLVED] soo confused.

    I am trying to display data from access base.
    this is what i have so far.

    VB Code:
    1. Dim MyConn As ADODB.Connection
    2. Dim MyRecSet As ADODB.Recordset
    3. Dim strName As String
    4. Dim strAddress As String
    5. Dim strPhone As String
    6.  
    7.  
    8. Private Sub Form_Load()
    9.  
    10.  
    11. MyRecSet.CursorLocation = adUseClient
    12. MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/" & "database.mdb;"
    13.  
    14. MyConn.Open
    15.  
    16. Set MyRecSet = MyConn.Execute("SELECT * FROM Patients")
    17.  
    18. End Sub

    i want the stuff to display in flexgrid or datagrid.

    how do i go about doing that?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: soo confused.

    A quick method to simply dump the contents of a recordset into a FlexGrid.

    VB Code:
    1. With Me.MSFlexGrid1
    2.     'set the total # rows and columns from the recordset
    3.     'assumes RecordCount is > 0
    4.     .Rows = MyRecSet.RecordCount + .FixedRows
    5.     .Cols = MyRecSet.Fields.Count + .FixedCols
    6.    
    7.     'select all "data" cells (not including any "Fixed" cells)
    8.     .Row = .FixedRows
    9.     .Col = .FixedCols
    10.     .RowSel = .Rows - 1
    11.     .ColSel = .Cols - 1
    12.    
    13.     'move the entire recordset into the grid
    14.     'ensure no fields contain a CRLF
    15.     'this will not work if the data of a field contains a Tab
    16.     .Clip = Replace(MyRecSet.GetString, vbNewLine, " ")
    17. End With

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: soo confused.

    it gives me an error.

    invalid row value
    heres the code

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.  
    4. MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/" & "database.mdb;"
    5. MyConn.Open
    6.  
    7. Set MyRecSet = MyConn.Execute("SELECT * FROM Patients")
    8.  
    9. With Form1.MSFlexGrid1
    10.     'set the total # rows and columns from the recordset
    11.     'assumes RecordCount is > 0
    12.     .Rows = MyRecSet.RecordCount + .FixedRows
    13.     .Cols = MyRecSet.Fields.Count + .FixedCols
    14.    
    15.     'select all "data" cells (not including any "Fixed" cells)
    16.     .Row = .FixedRows
    17.     .Col = .FixedCols
    18.     .RowSel = .Rows - 1
    19.     .ColSel = .Cols - 1
    20.    
    21.     'move the entire recordset into the grid
    22.     'ensure no fields contain a CRLF
    23.     'this will not work if the data of a field contains a Tab
    24.     .Clip = Replace(MyRecSet.GetString, vbNewLine, " ")
    25. End With
    26. End Sub
    Last edited by masfenix; May 7th, 2006 at 09:12 AM.

  4. #4

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: soo confused.

    nvmd i figured that out,

    but is there a way that if user clicks on a grid, they can edit the value? and the value is automatically changed in the database?

  6. #6

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