DLookup Question

  • Thread starter Thread starter Bunky
  • Start date Start date
B

Bunky

I have looked at this until I am cross-eyed. Hopefully, someone will help!

I have a table [StateAbbv] that has State names and the postal abbreviation
[Abbrev]. I have another table that I want to take the State identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF statement
like this
Forign: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) - It
gives me an error message that Microsoft cannot find '[Statey]'. Any help
would be greatly appreciated.
 
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table, ie
StateAbbv. It's saying it can't find Statey in the table because it's not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Roger,

I changed it like you said and now I am getting 'ERROR' in the column.

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)
???


Roger Carlson said:
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table, ie
StateAbbv. It's saying it can't find Statey in the table because it's not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Bunky said:
I have looked at this until I am cross-eyed. Hopefully, someone will help!

I have a table [StateAbbv] that has State names and the postal
abbreviation
[Abbrev]. I have another table that I want to take the State identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF
statement
like this
Forign: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) -
It
gives me an error message that Microsoft cannot find '[Statey]'. Any help
would be greatly appreciated.
 
That's because I was only looking at the DLookUp and not the whole
expression. Your DLookUp by itself is not an expression. The IIF needs an
expression to evaluate. I'm assuming here that if there is a match, you
want a 0 to appear in the Forgin column. If there is not a match, you want
a 1 to appear, correct?

If so, try this:
Forgin: IIf(Not IsNull(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" &
[Statey])),0,1)

Reason? If there is not a match, DLookUp will return a Null, so we test for
that with the IsNull function.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Bunky said:
Roger,

I changed it like you said and now I am getting 'ERROR' in the column.

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)
???


Roger Carlson said:
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table,
ie
StateAbbv. It's saying it can't find Statey in the table because it's
not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Bunky said:
I have looked at this until I am cross-eyed. Hopefully, someone will
help!

I have a table [StateAbbv] that has State names and the postal
abbreviation
[Abbrev]. I have another table that I want to take the State
identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF
statement
like this
Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) -
It
gives me an error message that Microsoft cannot find '[Statey]'. Any
help
would be greatly appreciated.
 
Roger forgot that the state abbreviation is likely a string, not a number.

Try


Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]='" & [Statey] &
"'"),0,1)

Exagerated for clarity, that's

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]= ' " & [Statey] & " '
" ),0,1)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Bunky said:
Roger,

I changed it like you said and now I am getting 'ERROR' in the column.

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)
???


Roger Carlson said:
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table,
ie
StateAbbv. It's saying it can't find Statey in the table because it's
not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Bunky said:
I have looked at this until I am cross-eyed. Hopefully, someone will
help!

I have a table [StateAbbv] that has State names and the postal
abbreviation
[Abbrev]. I have another table that I want to take the State
identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF
statement
like this
Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) -
It
gives me an error message that Microsoft cannot find '[Statey]'. Any
help
would be greatly appreciated.
 
Statey is not in the StateAbbv table; Abbrev is the abbreviation I wish to
check against. Statey is in the query being used as I/P to this query.

Question: Why the '&' in the line? what is it doing for you?

Roger Carlson said:
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table, ie
StateAbbv. It's saying it can't find Statey in the table because it's not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Bunky said:
I have looked at this until I am cross-eyed. Hopefully, someone will help!

I have a table [StateAbbv] that has State names and the postal
abbreviation
[Abbrev]. I have another table that I want to take the State identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF
statement
like this
Forign: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) -
It
gives me an error message that Microsoft cannot find '[Statey]'. Any help
would be greatly appreciated.
 
Take a look at this link: http://support.microsoft.com/kb/208786/EN-US/
and look specifically for this heading (halfway down the page): Specifying
Textual Criteria That Comes from a Field on a Form.

Short answer is that it inserts the *value* of the field on that actual row
of your query into the DLookUp. This means, of course, that the DLookUp
executed once for *each* row, which is why it can be such a resource hog.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Bunky said:
Statey is not in the StateAbbv table; Abbrev is the abbreviation I wish to
check against. Statey is in the query being used as I/P to this query.

Question: Why the '&' in the line? what is it doing for you?

Roger Carlson said:
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table,
ie
StateAbbv. It's saying it can't find Statey in the table because it's
not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Bunky said:
I have looked at this until I am cross-eyed. Hopefully, someone will
help!

I have a table [StateAbbv] that has State names and the postal
abbreviation
[Abbrev]. I have another table that I want to take the State
identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF
statement
like this
Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) -
It
gives me an error message that Microsoft cannot find '[Statey]'. Any
help
would be greatly appreciated.
 
Thank You BOTH!

It works just like I want it to.
Is there somewhere I could look to find a breakdown of this function? MS
Help is not helping me.

Thanks again!!!!

Douglas J. Steele said:
Roger forgot that the state abbreviation is likely a string, not a number.

Try


Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]='" & [Statey] &
"'"),0,1)

Exagerated for clarity, that's

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]= ' " & [Statey] & " '
" ),0,1)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Bunky said:
Roger,

I changed it like you said and now I am getting 'ERROR' in the column.

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)
???


Roger Carlson said:
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table,
ie
StateAbbv. It's saying it can't find Statey in the table because it's
not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

I have looked at this until I am cross-eyed. Hopefully, someone will
help!

I have a table [StateAbbv] that has State names and the postal
abbreviation
[Abbrev]. I have another table that I want to take the State
identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF
statement
like this
Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) -
It
gives me an error message that Microsoft cannot find '[Statey]'. Any
help
would be greatly appreciated.
 
Quite true. Thanks.

That being the case, perhaps the Not IsNull() is unnecessary. Still, it's
more explicit and it shouldn't hurt.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Douglas J. Steele said:
Roger forgot that the state abbreviation is likely a string, not a number.

Try


Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]='" & [Statey] &
"'"),0,1)

Exagerated for clarity, that's

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]= ' " & [Statey] & "
' " ),0,1)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Bunky said:
Roger,

I changed it like you said and now I am getting 'ERROR' in the column.

Forgin: IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)
???


Roger Carlson said:
If I'm reading this correctly, Statey is not in the StateAbbv table,
correct? The "Where" argument must have a field from the domain table,
ie
StateAbbv. It's saying it can't find Statey in the table because it's
not
there.

Try switching the fields: Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Abbrev]=" & [Statey]),0,1)

Notice too, that I took [Statey] out of the quotes.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

I have looked at this until I am cross-eyed. Hopefully, someone will
help!

I have a table [StateAbbv] that has State names and the postal
abbreviation
[Abbrev]. I have another table that I want to take the State
identifier
[Statey] and verify it is correct. So I wrote a DLookup in an IIF
statement
like this
Forign:
IIf(DLookUp("[Abbrev]","[StateAbbv]","[Statey]=[Abbrev]"),0,1) -
It
gives me an error message that Microsoft cannot find '[Statey]'. Any
help
would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DLookup and Nz 0
dlookup 2
XML - traversing in VB 1
Dlookup and Conditional Formatting 3
Trouble with DLookup 3
DLookUp 7
DLookup debacle 4
Dlookup Question! 5

Back
Top