DLookup HELP! Run-Time Error 2471

PaulDixie

New Member
Joined
May 7, 2007
Messages
39
Hi all,

Can you help me? I'm trying to work a DLookup in Access VBA, where I want to lookup the value of two strings (concatenated together) and find a matching value in a table.

This is part of the VBA but can't work out why the DLookup Isn't working - it recognises the 'UniqueRef' string okay with the right value, but it gives me Run-Time Error 2471.

Can someone tell me where I'm going wrong? I've looked all over the net and tried everything, but nothing works...

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
UniqueRef = ACOINo & ACOINo2

If DLookup("[ApiUniqueRef]", "[qryApiAPCAData]", "[ApiUniqueRef]='" & UniqueRef & "'") Then

'Confirm Record
Do
RV = WD_SendKey(100, "@2")
Loop Until RV = 0
RV = 4

Else

Msgbox "No Record"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Thanks
Paul
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
If UniqueRef is a Number then change your syntax to " & UniqueRef & " and not '" & UniqueRef & "'
 
Upvote 0
Thanks. What would be the whole peice of code then? I have changed the code, but it tells me I have a "Compile error Expected: list separator or)" code I have now is...

If DLookup("[ApiUniqueRef]", "[qryApiAPCAData]", "[ApiUniqueRef] = " & UniqueRef & ") Then
 
Upvote 0
if ACOINo & ACOINo2 are going to be numbers only then define it as long

Dim UniqueRef As Long
If DLookup("ApiUniqueRef", "qryApiAPCAData", "ApiUniqueRef = " & UniqueRef & "") Then

else may be string...
Dim UniqueRef As String
If DLookup("ApiUniqueRef", "qryApiAPCAData", "ApiUniqueRef = '" & UniqueRef & "'") Then

try this code.
Code:
[/FONT]
[FONT=Courier New]Dim UniqueRef As Long
UniqueRef = ACOINo & ACOINo2
If DLookup("ApiUniqueRef", "qryApiAPCAData", "ApiUniqueRef = " & UniqueRef & "") Then
Do
RV = WD_SendKey(100, "@2")
Loop Until RV = 0
RV = 4
Else
MsgBox "No Record"
End If[/FONT]
[FONT=Courier New]
 
Upvote 0
<s>Where do you get the error?</s>
Misread question.:oops:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top