Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with object error

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
US
If anyone knows the answer to this, could you please help me...

I have a form with a grid, and a data contol on it (datCust). I have placed this code in my form:

If datCust.Recordset.RecordCount > 0 Then
{do somthing....}
End If

Sometimes I get an error 3, Object variable or With block variable not set. I've traced it down to the above line.
I don't use data controls much, but sometimes it's a treat.

How can I check the object, thus avoiding the dreaded error.

P.S. I can't re-create the error, but it happends in my program once in a while in the field.
I'm using VB6 with sp3

Thanks :)
-Gary


They never have to knock if your door is always open.
 
have you Before the dataControl close the recordset ? Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
No, I checked for that. They never have to knock if your door is always open.
 
Whenever you get this error, try trapping the SQL statement and executing it in the database env., (Access or SQL Server whichever you are using).

Let me know what you find.
 
Huh? They never have to knock if your door is always open.
 
I am sorry if I was not clear in my response. Since you have a data control, I assume you must be attaching it to a table or executing a query to retrieve some records.

When you get the error, it is possible that your query is not returning any records and thus your error which says that the Object is closed.

So if you have a query, try executing it in the database which you are using, to confirm whether you actually get back records or not.

I hope I was able to make my point this time.
 
Possible is that you declare in the Load of a Form :

Sub Form_Load ()

Dim Test As Recordset

set Test = Opendatabase.Openrecordset("Table",dbOpenDynaset)
set Data1.Recordset = Test

On the Form you wil next code or is it in the load ?

is it on The form then you most declare ,the Dim Test As RecordSet in the Global Declarations of the Form

If datCust.Recordset.RecordCount > 0 Then
{do somthing....}
End If

a better way =

if datCust.Recordset.RecordCount = 0 then
Exit Sub
End If
Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
It's like this; The form has an DAO datacontrol and a True DB Grid 6.0 grid on it. You search the grid for a customers name. They click the grid and ...

------------------------------------------
Here's the code:
------------------------------------------

Private Sub grdDataGrid_Click()
grdDataGrid.PostMsg mClick
End Sub

------------------------------------------
This calls the PostEvent function:
------------------------------------------

Private Sub grdDataGrid_PostEvent(ByVal MsgId As Integer)
On Error GoTo grdDataGrid_PostEventErr

Select Case MsgId
Case mClick
If datCust.Recordset.RecordCount > 0 Then
'Enable the "Select" and "Done" buttons on the main screen toolbar
frmMain.tbMain.Tools("ID_CS_Select").Enabled = True
frmMain.tbMain.Tools("ID_CS_Done").Enabled = True
End If

Case mDblClick
CustSelect

End Select

Exit Sub
grdDataGrid_PostEventErr:
cER.LogError Err.Description, "grdDataGrid_PostEvent_CustSearch", Err.Number
Exit Sub
End Sub





They never have to knock if your door is always open.
 
Oké I tested with Trdbgrid an I think you have not select in the DataControl the property : RecordSource

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
What's that mean in english? They never have to knock if your door is always open.
 
Properties of the datacontrol ...

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
I thought you had something there, but I call frmCustomer.GetCustomer which sets the RecordSource in code then does a Me.show.
I was doing a Me.Move before setting the RecordSource though, which shows the form. If the pc is not fast enough, it may show the grid before setting the RecordSource.
They never have to knock if your door is always open.
 
I put the Me.Move statement after the code that sets up the datacontrol.
I'm just getting to these animals.

Thanks again..

Gary They never have to knock if your door is always open.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top