|
-
Jul 9th, 2001, 02:59 AM
#1
Thread Starter
Frenzied Member
Validating a table
How do I validate if a table named mytb is empty? I would like to decalare the code as
Code:
if mytb.empty = true then
...
but this is not possible.
-
Jul 9th, 2001, 04:38 AM
#2
Frenzied Member
You would have to either a) open a recordset of the contents of the table and check the .RecordCount property or b) run a
SELECT COUNT(*) AS RecordCount FROM MyTB
into a recordset and check the RecordCount field
Why not make a quick function;
Function EmptyTable(TblName As String) As Boolean
Dim tmpRS As New ADODB.Recordset
TmpRs.Open "SELECT COUNT(*) AS RecordCount FROM "+TblName
EmptyTable = Tmprs.Fields("RecordCount")=0
Tmprs.Close
End Function
Then you can use
If EmptyTable("MyTB") Then...
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Jul 9th, 2001, 05:02 AM
#3
Thread Starter
Frenzied Member
OK, but an error occurs running your code. It's an RTE 3709.
-
Jul 9th, 2001, 06:09 AM
#4
Frenzied Member
Oops - I forgot the ADO connection; try this;
Code:
Function EmptyTable(TblName As String, ADOConn as ADODB.Connection) As Boolean
Dim tmpRS As New ADODB.Recordset
TmpRs.Open "SELECT COUNT(*) AS RecordCount FROM "+TblName, AdoConn, AdOpenStatic, AdLockReadOnly
EmptyTable = Tmprs.Fields("RecordCount")=0
Tmprs.Close
End Function
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Jul 9th, 2001, 06:51 AM
#5
Thread Starter
Frenzied Member
Ok, what is then the statement for
If EmptyTable("MyTB", ???) Then...
?
-
Jul 9th, 2001, 06:53 AM
#6
Frenzied Member
You need to pass it a valid ADO connection;
so if you had done this
Dim MyConn AS New ADODB.Connection
MyConn.Open ".........."
You would use
If EmptyTable("MyTB", MyConn) Then...
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|