I tried but got the following error:
run-time error '91':
object variable or with block variable not set.
This error message highlights the first line where I try
to 'Set rsCount=db911 .....'
Perhaps, I missed something. Here is the code I tested:
Private Sub Form_Load()
Dim stDocName As String
Dim intSBCct As Integer
Dim intSCCct As Integer
Dim db911 As Database
Dim rsCount As DAO.Recordset
Set dbs = CurrentDb
Set rsCount = db911.OpenRecordset("test1",
dbOpenDynaset, dbReadOnly)
intSBCct = rsCount.Fields("Count")
Set rsCount = Nothing
Set rsCount = db911.OpenRecordset("test2",
dbOpenDynaset, dbReadOnly)
intSCCct = rsCount.Fields("Count")
If intSBCct > 0 Then
Me![CommandSBC].Enabled = True
Else
Me![CommandSBC].Enabled = False
End If
If intSCCct > 0 Then
Me![CommandIntrado].Enabled = True
Else
Me![CommandIntrado].Enabled = False
End If
End Sub
Michael
-----Original Message-----
Hi Mike,
You can do this by using code such as the following
(using DAO). Hopefully I won't make any typo's:
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("QueryName",dbOpenDynaset,
dbReadOnly)
Of course you would need to substitute the query name.
From here it should be the same as working with a
recordset drawn from a table (post back if you need
further help on that)
One note though, if you are only trying to count the
number of records in another table that meet certain
criteria, have you thought of using the Dcount()
function. Or, DFirst() to just see if any matches exist?
-Ted
-----Original Message-----
I need to be able to pass the result of a query to a VBA
Variable. Currently, I have only been able to do this
by
Changing the query into a make table query and then
Opening the table with VBA and assiging the variables.
There must be a better way.
As an example:
I have a Query that Counts the number of records with a
particular status. If the number of records with this
status is 0, I want to disable a button on a form.
Thanks!
Michael Carrillo
.
.