Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Type mismatch in VBA code

I get a type mismatch error when I run a report preview using this code:

Me.txtListingsTakenGoal = Nz(DLookup("[ListingsCount]", "tblMemberGoals", "[TeamMember] = Forms!frmSelectDateRangeAndMembers!txtMemberName") And "[GoalMonth] = Forms!frmSelectDateRangeAndMembers!txtMonth", 0)

I get no error when I just have this:

Me.txtListingsTakenGoal = Nz(DLookup("[ListingsCount]", "tblMemberGoals", "[TeamMember] = Forms!frmSelectDateRangeAndMembers!txtMemberName", 0)

Note: The field GoalMonth is a number field in the table.
Avatar of mbizup
mbizup
Flag of Kazakhstan image

If team member is text, try this:

Me.txtListingsTakenGoal = Nz(DLookup("[ListingsCount]", "tblMemberGoals", "[TeamMember] = '" &  Forms!frmSelectDateRangeAndMembers!txtMemberName & "') And "[GoalMonth] = Forms!frmSelectDateRangeAndMembers!txtMonth"), 0)

Open in new window


If it is a numeric ID:

Me.txtListingsTakenGoal = Nz(DLookup("[ListingsCount]", "tblMemberGoals", "[TeamMember] = " & Forms!frmSelectDateRangeAndMembers!txtMemberName & ") And "[GoalMonth] = Forms!frmSelectDateRangeAndMembers!txtMonth"), 0)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan 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
Avatar of SteveL13

ASKER

Is numeric and the last solution worked but now I have to add another form criteria.  I'll post another topic.