Solved

Type mismatch in VBA code

Posted on 2013-12-02
3
428 Views
Last Modified: 2013-12-02
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.
0
Comment
Question by:SteveL13
  • 2
3 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39689917
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

0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39689926
Correction:

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

Open in new window


Or for a numeric team member ID:

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

Open in new window

0
 

Author Comment

by:SteveL13
ID: 39689943
Is numeric and the last solution worked but now I have to add another form criteria.  I'll post another topic.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question