We help IT Professionals succeed at work.

easy 125 pts...

ccsbaby
ccsbaby asked
on
I have a data grid and some command buttons.  When the data grid is empty some of the command buttons cause error.  I tried this:

If grdDataGrid is null then
MsgBox("Message here")
End if

I also tried to replace the 'is null' with '= ""'

This obviously does not work.  Can anyone give me a working way to do this?  Thanks
Comment
Watch Question

Head of Software Services
BRONZE EXPERT
Commented:
Check the recordcount property of the underlying recordset:

If Data1.Recordset.RecordCount = 0 Then
  Msgbox "Grid is empty"
End If
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
SILVER EXPERT

Commented:
Hi ccsbaby,

How you connect the DataGrid, what is the associated DataSource?

Anyway, you can try to compare it with the DataSource of the DataGrid:

Example:

If Adodc.Recordset.RecordCount = 0 then
MsgBox("Message here")
'..
End if

..

regards
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
SILVER EXPERT

Commented:
slow typing.. :P

Author

Commented:
Sorry guys...Its connecting to an Access 2000 DB
ADODB connection,   OLEDB 4.0, etc.
TimCotteeHead of Software Services
BRONZE EXPERT

Commented:
Ok, so just use ADORecordset.RecordCount ( assuming of course that you have used adOpenStatic or a CursorLocation of adUseClient to open the recordset - otherwise you wont get the proper record count).

Commented:
have you tried

If grdDataGrid.DataSource.Recordset.EOF = true Then
    msgbox "GRID EMPTY"
Endif

Author

Commented:
mhowling:

method or data member not found

Commented:
Are you using a bound control/grid, or are you working with a disconnected recordset and populating the grid from within a procedure accessing the recordset object?

In your first column and first row, will there EVER an instance that the cell will empty?  You could check for data within a cell that will never contain an empty value, if properly populated.  If the cell returns a Null/Empty value, you know that your grid does not contain values.

Hope this "workaround" helps.
CArnold
BRONZE EXPERT
Author of the Year 2009

Commented:
Hi ccsbaby,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept TimCottee's comment(s) as an answer.

ccsbaby, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Per recommendation, force-accepted.

Netminder
CS Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.