RechDom function in Access

Marco -  
 kinder (sorry, pas logué) -
Hi everyone,
I'm really struggling to use this rechdom function in Access macros. The help is unusable or at least incomprehensible. If someone could explain the syntax of this function with an example, that would be great because I'm sure this function will save me. Thank you.

1 answer

Anonymous user
 
What's going wrong?
Well, since I don't know what the problem is, here it is: RechDom (or DLookup) returns the value of a field from a record that meets a criterion.
If you have a charcuterie table containing the fields sausage/appreciation:

saucisse de morteau 3
saucisson lorrain 5
bâton de berger 3
rosette 4
saucisson à l'ail 2

then if in your code you have
A=DLookup("[saucisse]","charcuterie","[appreciation]=3")

then A will have the value "saucisse de morteau" which is the value of the sausage field in the first record of charcuterie that meets the criterion.

Be careful, in a macro, thus with RechDom, replace commas with semicolons

if the criterion is on a string, put it in single quotes
ex:
RechDom("[appreciation]","charcuterie","[saucisse]='rosette'")
or
RechDom("[appreciation]","charcuterie","[saucisse] like 'sauc*'")
if you want the first one whose sausage starts with sauc

if your string contains an apostrophe (sneaky case), you split your expression in two and concatenate it by inserting chr(39) in the middle.

there you go, but I really don't know if that's what you wanted to know...
2
marco34 Posted messages 8 Status Member
 
Hello,

Thank you for your response, but it doesn't work. I have a Clients table with fields NomClient and TelClient. In a form, I want that when I leave the field linked to TelClient after entering a number, the corresponding name automatically appears in this form. So I created code related to the exit of the field linked to TelClient:
a=Form_FormReqCommande.TelClient.Value
Form_FormReqCommande.NomClient.Value=DlookUp("[NomClient]","Clients","[TelClient]='a'"
The spelling of the fields is correct, and TelClient is a string. But it doesn't find the value, since it remains equal to Null. Thank you
0
kinder (sorry, pas logué) > marco34 Posted messages 8 Status Member
 
2 things:
firstly, why are you putting ' around a since it's a variable? Remove the '
secondly, you are typically in a case where it would be worth having your form source a query linking the two tables, but well, that's another issue.
0
kinder (sorry, pas logué) > marco34 Posted messages 8 Status Member
 
and then, I don't understand what you mean by 'it remains equal to Null'.
well, quickly because I'm in a rush, when you enter a phone number, is it necessarily initially in the Clients table and in a single instance? it's a side question unrelated to the specific issue you are raising.
0