Link to home
Start Free TrialLog in
Avatar of Not2ruthless
Not2ruthless

asked on

vba DCount with 2 criteria

Hello,
I have created an unbound form called "frmAddTrainClasses".  On it I have a text field, "StudentID", and a ComboBox named "Class1" that obtains values from another table named tblClasses.

I am trying to count, via VBA, how many referrals in another qry that include BOTH the same StudentID AND ClassID.  It took me FOREVER to not get syntax errors but now am receiving TypeMisMatch errors.  I would appreciate any help.  Here it is below:

Private Sub ViewClass1_Click()
Dim ClassValue

If IsNull(Class1.Column(0)) = False Then
    Let ClassValue = Class1.Column(0) 'this is reporting correctly
    If  DCount("[ReferralID]", "qryAllReferrals", "[StudentID] = " & Me![StudentID] And "[ClassID] = " & ClassValue) > 0 Then
        blah
   else
       blah blah
   endif
endif
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Not2ruthless
Not2ruthless

ASKER

Thanks to you both!  Appreciate kno!wing the different syntax between text and numerical.  Happy Holidays