Hi Lisa,
Thanks for your post. According to your description, I am not quite clear
your accurate concern. Do you mean you want to return 0 when there is not
any records return form the query? Please try the following codes to see if
it meets your requirements.
//////////////////////////////////
Dim cnn1 As New ADODB.Connection
Dim cmd1 As ADODB.Command
Dim rst1 As ADODB.Recordset
'Create the connection to another database.
cnn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft Office\Office10\" & _
"Samples\Northwind.mdb;"
'Define and execute command to select all ProductID field 'values from a
single table.
Set cmd1 = New ADODB.Command
With cmd1
.ActiveConnection = cnn1
.CommandText = "Select ProductID from [Order Details]"
.CommandType = adCmdText
.Execute
End With
'Assign the return set to a recordset.
Set rst1 = New ADODB.Recordset
rst1.CursorType = adOpenStatic
rst1.LockType = adLockReadOnly
rst1.Open cmd1
MsgBox rst1.RecordCount
////////////////////////////////////////////
Note: Because I am not sure the version of Access on your side. I assume
you are using Access 2002 and the sample database is under "C:\Program
Files\Microsoft Office\Office10\Samples\Northwind.mdb". Do not forget the
add the ADO reference when you complie your Access database.
In that case, if there is not any record returned, the 0 will be returned
in the message box. Then, you can use your code to check the return value
and perform the appropriate action.
Please feel free post in the newsgroup if it addresses your problem.
Regards,
Michael Shao
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.