Grifter
01-10-2005, 02:43 PM
OK guys....i am using a butchered version of FlyGuy's function to view a flexgrid.....however....once i change record i need the grid to clear itself of the data and leave headers....
I used to used the mygrd.CLEARSTRUCTURE command but that is for some reason unavailable to me now.....i have tried the .Clear but this does not work...
any suggestions???
posting code just in case...
Private Sub fillgrid()
Dim adoConn As ADODB.Connection
Dim adoRST As ADODB.Recordset
On Error GoTo errHandler
' open the connection
Set adoConn = New ADODB.Connection
adoConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\cadetdb.mdb" & ";" _
& " Persist Security Info=False;Jet OLEDB:Database Password=sharpe;"
current = Text5.Text
' get a recordset
Set adoRST = New ADODB.Recordset
sql = "SELECT Campname AS Campname,Startdate AS 'Start Date',Enddate AS 'End Date' ,paid " _
& "AS Paid FROM Cadet, cadetcamp, camplist WHERE cadet.cadetno = cadetcamp.cadetid " _
& "AND cadetcamp.campid = camplist.campid AND cadet.cadetno = " & current & ";"
MsgBox sql
adoRST.Open sql, adoConn, adOpenKeyset, adLockReadOnly, adCmdText
With adoRST
If Not .EOF Then
FG_ShowRecordset MSFlexGrid1, adoRST
End If
.Close
End With
adoConn.Close
Set adoConn = Nothing
Set adoRST = Nothing
Exit Sub
errHandler:
MsgBox "An error occured." & vbLf & Err.Number & ": " & Err.Description, vbCritical
Set adoConn = Nothing
Set adoRST = Nothing
End Sub
Private Sub FG_ShowRecordset(myFG As MSFlexGrid, myRST As ADODB.Recordset)
Dim iField As Integer, iNofFields As Integer
Dim lRow As Long
Screen.MousePointer = vbHourglass
With myRST
.MoveFirst
iNofFields = .Fields.Count
End With
With myFG
.Redraw = False
.AllowUserResizing = flexResizeColumns
.ScrollTrack = True
.FixedCols = 0
.FixedRows = 0
.Cols = iNofFields
.Rows = 1
' setup the header
For iField = 0 To iNofFields - 1
.TextMatrix(0, iField) = myRST.Fields(iField).Name
Next iField
End With
With myRST
Do
' increase the number of rows
lRow = myFG.Rows
myFG.Rows = myFG.Rows + 1
' add the values to the current row
For iField = 0 To iNofFields - 1
If Not IsNull(.Fields(iField).Value) Then
myFG.TextMatrix(lRow, iField) = .Fields(iField).Value
End If
Next iField
' proceed to the next record
.MoveNext
Loop Until .EOF
End With
With myFG
.FixedRows = 1
.Redraw = True
End With
Screen.MousePointer = vbNormal
End Sub
I used to used the mygrd.CLEARSTRUCTURE command but that is for some reason unavailable to me now.....i have tried the .Clear but this does not work...
any suggestions???
posting code just in case...
Private Sub fillgrid()
Dim adoConn As ADODB.Connection
Dim adoRST As ADODB.Recordset
On Error GoTo errHandler
' open the connection
Set adoConn = New ADODB.Connection
adoConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\cadetdb.mdb" & ";" _
& " Persist Security Info=False;Jet OLEDB:Database Password=sharpe;"
current = Text5.Text
' get a recordset
Set adoRST = New ADODB.Recordset
sql = "SELECT Campname AS Campname,Startdate AS 'Start Date',Enddate AS 'End Date' ,paid " _
& "AS Paid FROM Cadet, cadetcamp, camplist WHERE cadet.cadetno = cadetcamp.cadetid " _
& "AND cadetcamp.campid = camplist.campid AND cadet.cadetno = " & current & ";"
MsgBox sql
adoRST.Open sql, adoConn, adOpenKeyset, adLockReadOnly, adCmdText
With adoRST
If Not .EOF Then
FG_ShowRecordset MSFlexGrid1, adoRST
End If
.Close
End With
adoConn.Close
Set adoConn = Nothing
Set adoRST = Nothing
Exit Sub
errHandler:
MsgBox "An error occured." & vbLf & Err.Number & ": " & Err.Description, vbCritical
Set adoConn = Nothing
Set adoRST = Nothing
End Sub
Private Sub FG_ShowRecordset(myFG As MSFlexGrid, myRST As ADODB.Recordset)
Dim iField As Integer, iNofFields As Integer
Dim lRow As Long
Screen.MousePointer = vbHourglass
With myRST
.MoveFirst
iNofFields = .Fields.Count
End With
With myFG
.Redraw = False
.AllowUserResizing = flexResizeColumns
.ScrollTrack = True
.FixedCols = 0
.FixedRows = 0
.Cols = iNofFields
.Rows = 1
' setup the header
For iField = 0 To iNofFields - 1
.TextMatrix(0, iField) = myRST.Fields(iField).Name
Next iField
End With
With myRST
Do
' increase the number of rows
lRow = myFG.Rows
myFG.Rows = myFG.Rows + 1
' add the values to the current row
For iField = 0 To iNofFields - 1
If Not IsNull(.Fields(iField).Value) Then
myFG.TextMatrix(lRow, iField) = .Fields(iField).Value
End If
Next iField
' proceed to the next record
.MoveNext
Loop Until .EOF
End With
With myFG
.FixedRows = 1
.Redraw = True
End With
Screen.MousePointer = vbNormal
End Sub