Missing Operator - Dlookup

Need another pair of eyes on this, I do not see anything wrong with this statement, however, I am getting Missing Operator error.

                varBefore = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = " & ctl.OldValue)

The first set of Dlookups work fine, do not see any differences in the syntax.

K

For Each ctl In frm.Controls
        If ctl.Tag = "Audit" Then
            If ctl.Name = "PartnerID" Then
                varBefore = DLookup("Partner", "TL_PartnerNames", "PartnerID = " & ctl.OldValue)
                varAfter = DLookup("Partner", "TL_PartnerNames", "PartnerID = " & ctl.Value)
            ElseIf ctl.Name = "IntAgency" Then
                varBefore = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = " & ctl.OldValue)
                varAfter = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = " & ctl.Value)
            Else
                varBefore = ctl.OldValue
                varAfter = ctl.Value
            End If

Open in new window

errormsg.png
Karen SchaeferBI ANALYSTAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
if the field  "IntAgencyRecID" is text, use this

 varBefore = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = '" & ctl.OldValue & "'")


or


varBefore = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = " & chr(34) & ctl.OldValue & chr(34))
0
Dale FyeOwner, Developing Solutions LLCCommented:
obviously either the OldValue or the Value of the control that is being evaluated is NULL.  Try:

varBefore = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = " & NZ(ctl.OldValue,0))
varAfter = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = " & NZ(ctl.Value,0))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:


if the field  "IntAgencyRecID" is text, use this

 varBefore = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = '" & nz(ctl.OldValue) & "'")


or


varBefore = DLookup("AgencyName", "TA_PartnerInternalAgency", "IntAgencyRecID = " & chr(34) & Nz(ctl.OldValue) & chr(34))
0
Karen SchaeferBI ANALYSTAuthor Commented:
Thanks for the great assist.

Karen
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.