Help me please...

RAYMOND HJ
10-25-2000, 08:21 AM
My problem is, I got a runtime error "Object variable or with block variable not set".

I'm using Acess and data control to connect to database as below:-


Option Explicit
Dim intRow As Integer

Private Sub Form_Load()
Data1.RecordSource = "SELECT * FROM Treatment WHERE Patient_Id = 4"

Msflexgrid1.Clear
Msflexgrid1.Row = 0

Msflexgrid1.Col = 0
Msflexgrid1.Text = "No."
Msflexgrid1.ColWidth(0) = 500
Msflexgrid1.FixedAlignment(0) = vbCenter

Msflexgrid1.Col = 1
Msflexgrid1.Text = "Name"
Msflexgrid1.ColWidth(1) = 1000
Msflexgrid1.FixedAlignment(1) = vbLeftJustify

intRow = 1

Do While Data1.Recordset!Patient_Id = 4 'this line error

Msflexgrid1.Row = intRow

Msflexgrid1.Col = 0
Msflexgrid1.Text = intRow
Msflexgrid1.Col = 1
Msflexgrid1.Text = Data1.Recordset!Name

intRow = intRow + 1
Data1.Recordset.MoveNext

If Data1.Recordset.EOF Then
Exit Sub
End If
Loop
End Sub

Thanks for any idea to solve this problem...

PWNettle
10-25-2000, 04:13 PM
Well, I'm not all-knowing about data control recordsets or looping thru such a recordset but I've never seen anything like:
<PRE> Do While Data1.Recordset!Patient_Id = 4</PRE>
Your Data1.RecordSet should contain all records for 'Patient_Id = 4' due to your recordsources's SQL:
<PRE> Data1.RecordSource = "SELECT * FROM Treatment WHERE Patient_Id = 4"</PRE>
I think a more conventional way to get at these records would be something like:
<PRE> Do While Not Data1.RecordSet.BOF And Not Data1.RecordSet.EOF
' Flexgrid populating code goes here
Data1.Recordset.MoveNext
Loop</PRE>
At least that's one way one could loop them with ADOish code...I'd think it'd work for a Data Control RecordSet too.

Good luck,
Paul

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum