tags:

views:

162

answers:

3

Hello

I am trying to use DLookup for a ValidationRule for a TextBox on a form in Access.

As per an example found on MSDN I used

dlookup("ABKUERZUNG", "tblABKUERZUNG", "ABKUERZUNG=[Forms]![frmMutBetriebspunkt]![BP_ABKUERZUNG]") is null

Which does not work: The expression you entered contains invalid syntax.

Now, if someone knew what and where exactly this invalid syntax is, I'd be grateful.

Thanks Rene

edit: corrected wrong ' to " (which was not the cause of the problem)

+2  A: 

EDITED

For Code:

If IsNull(dlookup( _
"ABKUERZUNG", "tblABKUERZUNG", _
"ABKUERZUNG=[Forms]![frmMutBetriebspunkt]![BP_ABKUERZUNG]")) Then

For a Validation Rule:

dlookup("ABKUERZUNG", "tblABKUERZUNG", "ABKUERZUNG=[Forms]![frmMutBetriebspunkt]![BP_ABKUERZUNG]")=Null
Remou
I am trying to enter the expression into the ValidationRule, and trying to put the expression within an IF .. THEN .. TRUE END IF still brings the same error message.
René Nyffenegger
Also, if I use the numeric primary key of the table instead of ABKUERZUNG, it doesn't change anything.
René Nyffenegger
Apologies - in that format delimters are not required. I note that you have a single quote at trhe start of the Where statement, it should be a double quote ("). Where do you have this code? In a module?
Remou
The ' is a mistake when I sort-of manually copied the text to stackoverflow. In the original code, I have a ". The code *is* the ValidationRule for a textBox on the form frmMutBetriebspunkt.
René Nyffenegger
I have edited my answer, I hope it helps.
Remou
A: 

You may want isolate the string you are creating for your filter, so you could check in the immediate window if the value is what you expect.

dim sFilter as String

sFilter = "ABKUERZUNG='" & [Forms]![frmMutBetriebspunkt]![BP_ABKUERZUNG] & "'"

dlookup("ABKUERZUNG", "tblABKUERZUNG", sFilter) is null
Jeff O
This is not true. Try it in the immediate window.
Remou
So use to doing it that way when coding, I didn't realize it is not required. Made changes.
Jeff O
Yes, but you're depending on the Access expression service to resolve the reference correctly in the guts of the DLookup() code, over which you have no control. I hardly ever use DLookup(), but if I did, I'd resolve the control reference before passing anything to it.
David-W-Fenton
+2  A: 

If you use a function in code, the parameter separator is the comma(,), but in the GUI-editor it is the semicolon (;). This could be your syntax error.

So try:

=Dlookup("field";"table";"where")
dwo
This is it! Thank you very much. For the record, I used a =DLookUp("ABKUERZUNG";"tblBETRIEBSPUNKT";"ABKUERZUNG=[Forms]![frmMutBetriebspunkt]![BP_ABKUERZUNG]") Is Nullin order to make sure that ABKUERZUNG doesn't already exist in the table.
René Nyffenegger
Er, what? Where is ";" a valid separater for function parameters? I cannot get it to be accepted anywhere in A2003. Is this, perhaps, a localization issue?
David-W-Fenton
If you use a function in a calculated form-field or report-field, you have to use the ; like in Excel. But I can tell that only for the german version of Office.
dwo