Problem with DLookUp

A

Audissée

Hello

First, appologies for my bad english.

I need help for the following problem. I'm using the Dlookup method to help
filling a field :

me![Name] = DLookUp("[Name]", "[Table_contact]","[Surname]= '" &
me![Surname] & "'")

This is the good syntax, but the problem is that it return nothing if the
field me![Surname] contains the character '. Otherwise, it is OK.

How can I solve this problem?

Thanks for help

Stephane DAYNAC
 
D

Dirk Goldgar

Audissée said:
Hello

First, appologies for my bad english.

I need help for the following problem. I'm using the Dlookup method
to help filling a field :

me![Name] = DLookUp("[Name]", "[Table_contact]","[Surname]= '" &
me![Surname] & "'")

This is the good syntax, but the problem is that it return nothing if
the field me![Surname] contains the character '. Otherwise, it is OK.

How can I solve this problem?

Thanks for help

Stephane DAYNAC

Unless [Surname] is likely to contain the " character, you can use this
criterion:

"[Surname]= """ & Me![Surname] & """"

An alternative is to use the Replace function on the value of
Me![Surname] to replace the quote character -- single or double -- with
two of the same character:

' using single quotes
"[Surname]= '" & Replace(Me![Surname], "'", "''") & "'"

or

' using double quotes
"[Surname]= """ & Replace(Me![Surname], """", """""") & """"
 
A

Audissée

Hello Dick

Thanks very much for the rapid answer.

Stéphane
De : "Dirk Goldgar" <[email protected]>
Répondre à : "Dirk Goldgar" <[email protected]>
Groupes : microsoft.public.access
Date : Sun, 21 Dec 2003 11:56:10 -0500
Objet : Re: Problem with DLookUp

Audissée said:
Hello

First, appologies for my bad english.

I need help for the following problem. I'm using the Dlookup method
to help filling a field :

me![Name] = DLookUp("[Name]", "[Table_contact]","[Surname]= '" &
me![Surname] & "'")

This is the good syntax, but the problem is that it return nothing if
the field me![Surname] contains the character '. Otherwise, it is OK.

How can I solve this problem?

Thanks for help

Stephane DAYNAC

Unless [Surname] is likely to contain the " character, you can use this
criterion:

"[Surname]= """ & Me![Surname] & """"

An alternative is to use the Replace function on the value of
Me![Surname] to replace the quote character -- single or double -- with
two of the same character:

' using single quotes
"[Surname]= '" & Replace(Me![Surname], "'", "''") & "'"

or

' using double quotes
"[Surname]= """ & Replace(Me![Surname], """", """""") & """"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
T

Tom Wickerath

In addition to Dirk Goldgar's answer, I recommend avoiding the use of reserved words for
the names of objects or controls in your database. You appear to have a table or query
named "Name" and a form or report control with the same name. This is a reserved word in
Access.

Reserved Words in Microsoft Access
http://support.microsoft.com/?id=209187

Tom
_________________________________________


Hello

First, appologies for my bad english.

I need help for the following problem. I'm using the Dlookup method to help
filling a field :

me![Name] = DLookUp("[Name]", "[Table_contact]","[Surname]= '" &
me![Surname] & "'")

This is the good syntax, but the problem is that it return nothing if the
field me![Surname] contains the character '. Otherwise, it is OK.

How can I solve this problem?

Thanks for help

Stephane DAYNAC
 
A

Audissée

Hello every one

The name of examples i have send with my mail are for exemple only. The reel
names I use are not reserved words.

I'm not sure I have explain the problem correctly. It is not the name of
controls or objets that make the problem. It is their content.

I take another example :

me![The_name] = DLookUp("[The_name-target]", "[Table_target]","[The
Surname_target]= '" & me![The_surname] & "'")

I have this programmation on an after update field call The_Surname.
It has to search the corresponding name ("The_name_target") in the Table
called "Table_target" to automatically fill the current form field
"The_name".

We supposed "The_surname" to be a key field in the "Table_contact".
So, for every "The-Surname" correspond only one "The_name".
It'll be difficult to explain briefly but I don't want to use the
traditionnal relation between Table to obtain The_name.


If The_surname = Dupond, it return the corresponding name "The_name" of
Mister Dupond

If the_surname = O'Brien, it doesn't work because of the character'.

Every time the name contain the character ' Dlookup return nothing.

And it's problematic to limit the_surname to have no " ' " in it.

I hope the explanation are clear and thanks to every one for according some
time to read my mail and respond

Sincerly

Stéphane
 
D

Dirk Goldgar

Audissée said:
Hello every one

The name of examples i have send with my mail are for exemple only.
The reel names I use are not reserved words.

I'm not sure I have explain the problem correctly. It is not the name
of controls or objets that make the problem. It is their content.

I take another example :

me![The_name] = DLookUp("[The_name-target]", "[Table_target]","[The
Surname_target]= '" & me![The_surname] & "'")

I have this programmation on an after update field call The_Surname.
It has to search the corresponding name ("The_name_target") in the
Table called "Table_target" to automatically fill the current form
field "The_name".

We supposed "The_surname" to be a key field in the "Table_contact".
So, for every "The-Surname" correspond only one "The_name".
It'll be difficult to explain briefly but I don't want to use the
traditionnal relation between Table to obtain The_name.


If The_surname = Dupond, it return the corresponding name "The_name"
of Mister Dupond

If the_surname = O'Brien, it doesn't work because of the character'.

Every time the name contain the character ' Dlookup return nothing.

And it's problematic to limit the_surname to have no " ' " in it.

I hope the explanation are clear and thanks to every one for
according some time to read my mail and respond

Sincerly

Stéphane

Stéphane, the answers you've been given should have solved this problem.
Have they not done so?
 
J

John Vinson

If The_surname = Dupond, it return the corresponding name "The_name" of
Mister Dupond

If the_surname = O'Brien, it doesn't work because of the character'.

The apostrophe causes the problem because it is being interpreted as
the closing quote delimiter - you open the criterion in the DLookUp
with ', and it sees the apostrophe as the closing '.

Use " instead: to include a " inside a string delimited with ", use
two consecutive " characters.

me![The_name] = DLookUp("[The_name-target]", "[Table_target]","[The
Surname_target]= """ & me![The_surname] & """")
 
A

Audissée

Thanks a lot to Dirk and John.
The use of the two conscutive character solve the problem.

Sincerly

Stéphane
De : John Vinson <jvinson@STOP_SPAM.WysardOfInfo.com>
Répondre à : (e-mail address removed)
Groupes : microsoft.public.access
Date : Mon, 22 Dec 2003 09:45:43 -0700
Objet : Re: Problem with DLookUp (v2)

If The_surname = Dupond, it return the corresponding name "The_name" of
Mister Dupond

If the_surname = O'Brien, it doesn't work because of the character'.

The apostrophe causes the problem because it is being interpreted as
the closing quote delimiter - you open the criterion in the DLookUp
with ', and it sees the apostrophe as the closing '.

Use " instead: to include a " inside a string delimited with ", use
two consecutive " characters.

me![The_name] = DLookUp("[The_name-target]", "[Table_target]","[The
Surname_target]= """ & me![The_surname] & """")
 

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

VBA - exporting serial letters to single documents 0
Problem with apostroph 11
Dlookup 7
Dlookup Help Please 8
DLookUp #Error 7
FROM and JOIN Problems 1
Dlookup Problem Text VS Number type 7
DLookUp Function 11

Top