Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Dlookup Type Mismatch
Kristy Duncan 
    
5 years ago
I have a very large table with information that I am trying to perform a dlookup on. I currently have a query to retrieve a reimbursement rate, based on zip code, providers licensure level, and place of service. Per Adams guidance, I decided to add an IF function for facility vs non-facility rate.

When I try to add the remaining three criteria, I keep getting type mismatch. When I run the separately, access will run without an error. Am I missing quotes or adding too many? I defined variables to try to simplify the code, thinking it would be cleaner.

This is what I have:

Private Sub Submit_Click()

Dim r1 As Variant
Dim L As Variant
Dim C1 As Variant
Dim LL As Variant

L = CarrierLocalityTxt
C1 = Code1
LL = LicenseCombo

r1 = DLookup("NonFacilityRate", "CMSCarrierLicenseRates2021AT", "CarrierLocality = """ & L & """" And "LicenseLevel = """ & LL & """" And "HCPCS = """ & C1 & """")

Check = r1

End Sub
Adam Schwanz  @Reply  
           
5 years ago
Oh boy, these are always fun. I think this is right

r1 = DLOOKUP("NonFacilityRate","CMSCarrierLicenseRates2021AT","CarrierLocality=""" & L & """" & " AND LicenseLevel=""" & LL & """" & " AND HCPS=""" & C1 & """")
Scott Axton  @Reply  
        
5 years ago
I personally do NOT like Variant data types except in a very few instances.  Variant can throw errors in my experience.  
My opinion is you should use the same data type in your Dim as the type of data you are bringing into that variable.

Access does a pretty good job of determining what the data type is BUT it can get it wrong.
This  could be the reason for your data type mismatch.
Richard Rost  @Reply  
          
5 years ago
Scott is correct. I hate variants too... they should be on the Evil list. R1 should be Dim'd as whatever data type NonFacilityRate is in your table. Looks like the others are all strings. Do that. :)
Kristy Duncan OP  @Reply  
    
5 years ago
THANK YOU SO MUCH! I removed the variants for everything except r1. Am I the only person that pumps my fists and cheers when the DB does what they want?! :D
Richard Rost  @Reply  
          
5 years ago

Richard Rost  @Reply  
          
5 years ago
From the name NonFacilityRate, I'm guessing that's a money value. Dim it as Currency.
Kristy Duncan OP  @Reply  
    
5 years ago
Another question: Im pretty sure this could have been simplified, but I have this code listed out 15 times, so the user can search for up to 15 codes at once. My first version allowed for one at a time. Is there a way to exit the sub after the last code is entered? I tried if isnull(C2) or C2= then exit sub before the line of code for C2, but it didnt seem to help. The time it is taking to populate makes it seem like its still going through each line, even if there isnt a code entered.
Scott Axton  @Reply  
        
5 years ago
Kristy you are obviously doing stuff that is pretty advanced.  I see by your badge that you have only started the Beginner Series.  Would you please give us a little background of your experience with Access, or programming in general, so we know how basic or not to make our answers.

If you are listing this code 15 times it should be in its own Sub procedure.

Here are some links to get you started:

Introduction to Access VBA

NZ Function

Access Search Seminar
Really look into the Search Seminar.  It is one that has stood the test of time and as a TechHelp member you get a discount on the course.  Refer to the email Richard sent you when you joined.
Kristy Duncan OP  @Reply  
    
5 years ago
Hi Scott! My background: I took computer programming, Visual Basic,  classes in high school and really enjoyed it. I had one course in college that briefly touched on Access. During my last maternity leave, 9 months ago, I started watching Access videos and built two databases to help with my work. I like to work smarter, not harder :) Ive literally watched HOURS of videos on Access and have been able to do everything Ive wanted so far. Im now working on a database to be used by multiple departments. I feel that Im a quick learner, and I am good at mapping out what I want my databases to do. I just dont know how to make it all come together. I understand things at the simple level, but I want to challenge myself and make this database do more.

Long story short, Ive realized I really enjoy programming, but I know Im far behind. I started watching videos about Python coding, but I figured Id should complete this project before I try to learn a different language. :)
Scott Axton  @Reply  
        
5 years ago
Thanks for that.  This will help a lot in answering future questions!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/2/2026 8:28:56 AM. PLT: 1s