domain count or sum

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to cancel the action if a user deselects a check box that the
domain count for that specific checkbox (blnAdmin) < 1. There has to be at
least one record with the check box = True. I have played around with this
and can't seem to get it to work. On the error when it highlights the line
yellow it show the "adminX = 0". What am I doing wrong or any better
sugestions?

------------start of code-----------------
Private Sub Admin_BeforeUpdate(Cancel As Integer)
Dim adminX As Integer

adminX = DCount([Admin], "Employee", "Admin = -1") //this line is
yellow
If adminX <= -1 Then
MsgBox "You must have at least 1 adminstrator!"
Cancel = True
End If
End Sub

-------------end of code---------------
 
I am trying to cancel the action if a user deselects a check box that the
domain count for that specific checkbox (blnAdmin) < 1. There has to be at
least one record with the check box = True. I have played around with this
and can't seem to get it to work. On the error when it highlights the line
yellow it show the "adminX = 0". What am I doing wrong or any better
sugestions?

------------start of code-----------------
Private Sub Admin_BeforeUpdate(Cancel As Integer)
Dim adminX As Integer

adminX = DCount([Admin], "Employee", "Admin = -1") //this line is
yellow

The first argument to DCount must be a *text string* - not a field
name. Since you're just counting records in a table, I'd just use

DCount("*", "Employee", "Admin = -1")


John W. Vinson[MVP]
 
Back
Top