Full Version: Why Won't This DLookup Work?
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
KStarosta
I am using the following DLookup functions to set the proper values in three separate comboboxes, in the Form Load event...

CODE
Me.cboFRNDrafter = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=" & Forms![frmHIREdit]![txtHIRID] And "[FRNDrafter]=" & -1)
Me.cboFRNPeer = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=" & Forms![frmHIREdit]![txtHIRID] And "[FRNPeer]=" & -1)
Me.cboFRNSRO = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=" & Forms![frmHIREdit]![txtHIRID] And "[FRNSRO]=" & -1)



tblHIRFRN = associative table, resolving a many-to-many relationship between tblHIR and tblFRN. It contains the following attributes:
- HIRFRNID (autonumber key)
- HIRID (primary key from tblHIR)
- FRNID (primary key from tblFRN)
- FRNDrafter (Yes/No datatype, indicating type of FRN record)
- FRNPeer (Yes/No datatype, indicating type of FRN record)
- FRNSRO (Yes/No datatype, indicating type of FRN record)

Each individual HIR record will have three FRN records, therefore there will be three rows for each HIR in the tblHIRFRN table. The Yes/No datatype is to indicate the TYPE of FRN.

Why are the three DLookups returning a value of NULL, instead of the FRNID like I thought they would?

Thanks very much!

- Keith
Clippit
Move the And inside the quotes and add an & and a space.

eg
"[HIRID]=" & Forms![frmHIREdit]![txtHIRID] & " And [FRNDrafter]=" & -1

Edited by: Clippit on Mon Mar 30 8:31:51 EDT 2009.
larrysteele
While you're at it, no need to concatenate the constant:

"[HIRID]=" & Forms![frmHIREdit]![txtHIRID] & " And [FRNDrafter] = -1 "

HTH,
Larry
KStarosta
Thanks for the help, guys...but I am still having an issue. Here is the code that I am now using, after incorporating the first example...

CODE
Me.cboFRNDrafter = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=" & Forms![frmHIREdit]![txtHIRID] & " And [FRNDrafter]=" & -1)
Me.cboFRNPeer = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=" & Forms![frmHIREdit]![txtHIRID] & " And [FRNPeer]=" & -1)
Me.cboFRNSRO = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=" & Forms![frmHIREdit]![txtHIRID] & " And [FRNSRO]=" & -1)


The code is still returning a NULL value where it should be bringing back the FRNID ID for the proper row in the combobox.

I am curious....do I somehow need to qualify the name of the checkbox fields with the table name, or is that accounted for earlier in the line, by indicating "tblHIRFRN"?

Thanks!!

- Keith
fkegley
Is HIRID type TEXT?
CyberCow
If the table field [HIRID] and the references to the form controls are text values (strings), you need to add the single quote warappers . . .
CODE
Me.cboFRNDrafter = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=[color="red"]'[/color]" & Forms![frmHIREdit]![txtHIRID] & "[color="red"]'[/color] And [FRNDrafter]= -1")
Me.cboFRNPeer = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=[color="red"]'[/color]" & Forms![frmHIREdit]![txtHIRID] & "[color="red"]'[/color] And [FRNPeer]= -1")
Me.cboFRNSRO = DLookup("[FRNID]", "tblHIRFRN", "[HIRID]=[color="red"]'[/color]" & Forms![frmHIREdit]![txtHIRID] & "[color="red"]'[/color] And [FRNSRO]= -1")
(the -1's need not be excluded from within the dbl-quotes)

hope this helps
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.