oasisoasisoasisoasis
asked on
FlexGrid display problem
Could someone please help me??? I am creating a database (access) Visual basic program. In my code I have the line Set Me.MSFlexGrid1.DataSource = rs, where I try to display data from a recordset into a grid. I'm using ADO. I keep getting this error runtime error 91 object variable or with block variable not set. Is this because I am missing a reference ? Or that I am trying to use me.SOMETHING, and I need to configure VB to let me do that?
TIA!!!!!
Cheers!
TIA!!!!!
Cheers!
ASKER
Private Sub s1_Click()
Dim datafile As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
datafile = App.Path & "\TrackCom Database.mdb"
' Create a connection to the database
Set cn = New ADODB.Connection
cn.Open ("Provider=Microsoft.Jet.O LEDB.4.0;D ata Source=" & datafile & ";Persist Security Info=False")
' Create a recordset that the MSFlexgrid will use to display records from
Set rs = New ADODB.Recordset
With rs
' Attach recordset to connection
.ActiveConnection = cn
'Make sure the data will be Updatable
.CursorLocation = adUseClient
.CursorType = adOpenStatic
' Open recordset using SQL SELECT statement to select records
.Open ("SELECT * FROM Hardware")
End With
Set MSFlexGrid1.DataSource = rs.DataSource!!!!!!!!DOES NOT LIKE THIS LINE
' Highlight row in MS Hierarchical Flex Grid
' Call HighlightCorrectRow
End Sub
Dim datafile As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
datafile = App.Path & "\TrackCom Database.mdb"
' Create a connection to the database
Set cn = New ADODB.Connection
cn.Open ("Provider=Microsoft.Jet.O
' Create a recordset that the MSFlexgrid will use to display records from
Set rs = New ADODB.Recordset
With rs
' Attach recordset to connection
.ActiveConnection = cn
'Make sure the data will be Updatable
.CursorLocation = adUseClient
.CursorType = adOpenStatic
' Open recordset using SQL SELECT statement to select records
.Open ("SELECT * FROM Hardware")
End With
Set MSFlexGrid1.DataSource = rs.DataSource!!!!!!!!DOES NOT LIKE THIS LINE
' Highlight row in MS Hierarchical Flex Grid
' Call HighlightCorrectRow
End Sub
ASKER
I used Set.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please use MSHFLEXGRID(Hierarchical) rather than MSFLEXGRID
u shoud write :
'========================
'Set MSFlexGrid1.DataSource = rs
'=========================
not
'========================= ===
'Set MSFlexGrid1.DataSource = rs.DataSource
'========================= ====
if it doesn't work, there is another method :
'==================
MSFlexGrid.Cols = Rs.Fields.Count
With RS
do While Not .EOF
MSFlexGrid.AddItem vbtab & .Fields(0) & vbtab & .Fields(1) & vbtab & Fields(2) 'until your last fields....
.movenext
Loop
End With
'In the first u can Define the Widht of Cols and the title of each Cols.
the second method is more better than to set DataSource.
'====================
'========================
'Set MSFlexGrid1.DataSource = rs
'=========================
not
'=========================
'Set MSFlexGrid1.DataSource = rs.DataSource
'=========================
if it doesn't work, there is another method :
'==================
MSFlexGrid.Cols = Rs.Fields.Count
With RS
do While Not .EOF
MSFlexGrid.AddItem vbtab & .Fields(0) & vbtab & .Fields(1) & vbtab & Fields(2) 'until your last fields....
.movenext
Loop
End With
'In the first u can Define the Widht of Cols and the title of each Cols.
the second method is more better than to set DataSource.
'====================
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- PAQ and point No Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
MYLim
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
- PAQ and point No Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
MYLim
EE Cleanup Volunteer
Dim rs As new ADODB.Recordset
or
Set rs = new ADODB.Recordset
:)