473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VBA Dlookup with two criteria not working

I am getting a runtime error - data mismatch in criteria expression. Any assistance to get this code working would be very much appreciated.

The State field on the Form frmVehicleDetails is an unbound field.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Situation_Change()
  3.  
  4. Forms!frmVehicleDetails!State.Value = DLookup("[State]", "[tblSituation]", "[SituationID]='" & [Forms]![frmVehicleDetails]![Situation] & "' AND [QuoteID]= '" & [Forms]![frmVehicleDetails]![QuoteID] & "'")
  5.  
  6.  
  7. End Sub
  8.  
  9.  
Jul 20 '11 #1
2 2098
Adam Tippelt
137 100+
Assuming that your ID fields are integers (as is the norm for ID fields), you've wrapped them in single quotes when this isn't required - this is only needed for string based fields.

Try this:

Expand|Select|Wrap|Line Numbers
  1. Forms!frmVehicleDetails!State.Value = DLookup("[State]", "[tblSituation]", "[SituationID]=" & [Forms]![frmVehicleDetails]![Situation] & " AND " & "[QuoteID]=" & [Forms]![frmVehicleDetails]![QuoteID])
Adam.
Jul 20 '11 #2
Thanks Adam, I knew it would be something simple that I had not thought of. That worked perfectly. Cheers.
Jul 20 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jack | last post by:
What is the syntax for the criteria in DLookup in a subform to refer to a control (MyControl) on the subform? I have tried the following and none seem to work: " = " &...
2
by: chris.thompson13 | last post by:
I am having a problem setting the criteria part of the DLookup method correctly and am consequently getting an error message. I have a database of staff duties, part of which is a query (qryDaily)...
21
by: Thelma Lubkin | last post by:
I would like my DLookup criteria to say this: Trim(fieldX) = strVar: myVar = _ DLookup("someField", "someTable", "Trim(fieldX) = '" & strVar & '") I don't believe that this will work, and I...
3
MSeda
by: MSeda | last post by:
I have a loop that is controlled by a Dlookup statement with two criteria. Both criteria fields are checkboxes. I have tried an assortment of quotation marks in the criteria section and cannot get...
11
by: vkong85 | last post by:
I'm creating a database for work and i've run into a snag. Currently i'm using to nested dlookup statements and they are searching for certain criteria in order to find the correct value the...
4
by: andy143vivi | last post by:
hi, whats wrong with this code? If Me.txtPassword.Value = DLookup("", "User", "='" & Me.txtUsername.Value & "'") Then DoCmd.OpenForm "frmDetails" Else MsgBox "Wrong Log In details!",...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
4
by: Soulspike | last post by:
Hello all. Currently I am still useing access97 (sad I know) and I can not seem to get this dlookup function in my vb code to work. I keep getting a type mismatch error when I run the code. I...
17
by: jasmineeyes | last post by:
i've beat my head on the table for this n spent hours searching the net but i cant find out whats wrong.. (btw, i'm pretty new to access..) i've got a Customers table with information on...
7
by: Adam Tippelt | last post by:
If DLookup("TS_ID", "TestsForScripts", "=" & Me.Ref_ID & " AND " & "='" & Me.ExpectedResult & "'") = "" Then Can anyone see anything wrong with this code? It keeps throwing up a Run Time Error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.