OK, looking closer, both DCount() functions are written incorrectly. Yes, Access evaluates the function, but the criteria should be written correctly.
The value for PersonnelID should be concantated:
Code:
'this one does not concatenate the referenced value
If DCount("*", "tblPropertyPass", "[PersonnelID] = [Forms]![frmPersonnel].[PersonnelID] AND [isActive] = true") = 0 Then
'this one does concatenate the referenced value
If DCount("*", "tblPropertyPass", "[PersonnelID] = " & [Forms]![frmPersonnel].[PersonnelID] & " AND [isActive] = true") = 0 Then
Code:
Public Sub updateButtons()
1 If DCount("*", "tblPropertyPass", "[PersonnelID] = " & [Forms]![frmPersonnel].[PersonnelID] & " AND [isActive] = true") = 0 Then
2 Me.btnClose.Enabled = False
3 Me.btnEditProperty.Enabled = False
4 Me.btnNew.Enabled = True
5 Else
6 Me.btnClose.Enabled = True
7 Me.btnEditProperty.Enabled = True
8 Me.btnNew.Enabled = False
9 End If
End Sub
Disregarding the table names, this is what the sub does:
Line #1: Count the records in a table where the PersonnelID equals the value on a form in a control named "PersonnelID". If the count equals 0, do the following:
Line #2: disable the button named btnClose
Line #3: disable the button named btnEditProperty '(btnEditTelework for the other sub)
Line #4: enable the button named btnNew
Line #5 Else '(DCount was not equal to 0)
Line #6: enable the button named btnClose
Line #7: enable the button named btnEditProperty '(btnEditTelework for the other sub)
Line #8: disable the button named btnNew
So the code sets the state of 3 buttons.
In form "frmPersonnel", are there buttons named "btnClose", "btnNew" and (maybe) "btnEditPersonnel"?