0
votes

Im trying to Dcount LetterSent1Bool Field for the current record that is open using a button.

So What i would like is: If the LetterSent1bool Field is Greater Than Zero (i.e 1) then MsgBox, Else Run Query.

So far I have:

DoCmd.SetWarnings False
If DCount("[LetterSent1Bool]", "dbo_T_Volunteers" & Me!VolunteerID) > 0 Then

MsgBox "ERROR !     This Volunteer has already received this Letter ,"
Else

But this code seems to query the whole field on all records. How do i Limit to the open record?

1

1 Answers

1
votes

DCount does not get the field's value, but counts the number of different rows for the specific table based on the specific field.

What you need is DlookUp

If(Nz(DLookUp("[LetterSent1Bool]", "dbo_T_Volunteers", _
        "[VolunteerIDField] = '" & Me!VolunteerID & "'"))) > 0

To look up the value of the field in that table for the specific record.