Results 1 to 2 of 2

Thread: Populating a grid with data from access

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    3

    Populating a grid with data from access

    Hey guys. I'm working in VBA with Microsoft Access to create a program that will be able to draw up quote estimations. Basically, a user will be able to select he features he/she wants and at the end, it will produce a little report with a cost estimation. I'm having two major problems.

    1) I was wondering if there is a way I can create a grid on one of the tabs that will populate itself with information from the database. It would be a pain to have to create a text box and input box for each selection on each tab, since in one of the tabs, there are over 20+ selections. I'm trying to save time, as I have to have this done by Friday morning.

    2) My second problem is, the program is a form with multiple tabs at the top. I need a way to implement a next button that will change between tabs. Any suggestions?

    Thanks in advance!

    P.S. I know I'm not being totally specific, I'm really rushed on time. If you need a specific question answered, I'll be watching this post like a hawk, so I should reply within seconds. Thanks again.

  2. #2
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208

    Re: Populating a grid with data from access

    Hello,

    I've included code to do just this. You can drag a Flexgrid onto one of the tab and then use my FillFlex function to fill the grid with data.

    The FillFlex function is called like this for example

    FillFlex "select * from users",Me.Flexgrid1

    VB Code:
    1. Function FillFlex(sql As String, flx As MSFlexGrid)
    2. On Error GoTo errhandler
    3.     Dim adors As DAO.Recordset
    4.     Set adors = Currentdb.OpenRecordset(sql)
    5.     If Not adors.EOF And Not adors.BOF Then
    6.         i = 0
    7.         With flx
    8.             .Rows = 2
    9.             .FixedRows = 1
    10.             .Clear
    11.             .Row = 0
    12.             .Cols = adors.Fields.Count
    13.            
    14.             i = 0
    15. 'You can set the column width
    16.             For Each fld In adors.Fields
    17.                 .Col = i
    18.                     Select Case i
    19.                     Case Is = 1 'Zone
    20.                         .ColWidth(i) = 900
    21.                     Case Is = 2 'Site
    22.                         .ColWidth(i) = 1400
    23.                     Case Is = 3 'Site Group
    24.                         .ColWidth(i) = 1400
    25.                     Case Is = 4 'Equipment
    26.                         .ColWidth(i) = 1000
    27.                    Case Else
    28.                         .ColWidth(i) = 730
    29.                     End Select
    30.                
    31.                 .Text = fld.Name
    32.                 i = i + 1
    33.             Next
    34.             adors.MoveFirst
    35.             While Not adors.EOF
    36.                .Row = .Rows - 1
    37.                i = 0
    38.                 For Each fld In adors.Fields
    39.                     .Col = i
    40.                     .Text = ""
    41.                     If Not IsNull(fld) Then
    42.                          .Text = Trim(fld)
    43.                     End If
    44.                     i = i + 1
    45.                    Next
    46.                .Rows = .Rows + 1
    47.                adors.MoveNext
    48.             Wend
    49.  
    50.  
    51.         .FixedCols = 1
    52.         .Rows = .Rows - 1
    53.     End With
    54.     End If
    55.     Set adors = Nothing
    56.     Screen.MousePointer = vbDefault
    57.     Exit Function
    58. errhandler:
    59.     MsgBox Err.Description
    60.  
    61. End Function
    Last edited by Killazzz; Feb 26th, 2006 at 03:39 PM.

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