error control

joe789

Registered User.
Local time
Today, 06:15
Joined
Mar 22, 2001
Messages
154
Hi Folks,

I am finalizing a program I have written by creating some error controls/warning messages. The code below doesn't want to work ... I think I am doing something stupid, but can't seem to find out how to get it to work. I have used the exact same code without the DoCmd.RunSQL and instead with other error tests such as comparing stuff in text boxes and what not and it has worked perfectly, so I think it is something I am doing wrong with passing the result of the SQL to the variable? In essance, the code checks to see if any lines exist in a table ... if no lines exist in a table, a message box is returned stating that. Any help would be appreciated.


Private Sub Command39_Click()

Dim countoflines As Integer

If DoCmd.RunSQL("select count(*) from MyTableName") = 0 Then
MsgBox ("You do not have anything to create a table from")
GoTo done
End If


done: MsgBox ("Your table has records in it")

End Sub
 
A query does not return a value, even a "count" query like the one you've got. Queries return records (or they perform actions like in delete or append queries).

You could open the query using DAO or ADO, then get a recordcount. But since we're working with a stored table, you can take the simpler, slower route and use the Dcount function to count the records.
 

Users who are viewing this thread

Back
Top Bottom