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.
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:
Function FillFlex(sql As String, flx As MSFlexGrid)
On Error GoTo errhandler
Dim adors As DAO.Recordset
Set adors = Currentdb.OpenRecordset(sql)
If Not adors.EOF And Not adors.BOF Then
i = 0
With flx
.Rows = 2
.FixedRows = 1
.Clear
.Row = 0
.Cols = adors.Fields.Count
i = 0
'You can set the column width
For Each fld In adors.Fields
.Col = i
Select Case i
Case Is = 1 'Zone
.ColWidth(i) = 900
Case Is = 2 'Site
.ColWidth(i) = 1400
Case Is = 3 'Site Group
.ColWidth(i) = 1400
Case Is = 4 'Equipment
.ColWidth(i) = 1000
Case Else
.ColWidth(i) = 730
End Select
.Text = fld.Name
i = i + 1
Next
adors.MoveFirst
While Not adors.EOF
.Row = .Rows - 1
i = 0
For Each fld In adors.Fields
.Col = i
.Text = ""
If Not IsNull(fld) Then
.Text = Trim(fld)
End If
i = i + 1
Next
.Rows = .Rows + 1
adors.MoveNext
Wend
.FixedCols = 1
.Rows = .Rows - 1
End With
End If
Set adors = Nothing
Screen.MousePointer = vbDefault
Exit Function
errhandler:
MsgBox Err.Description
End Function