PC Review


Reply
Thread Tools Rate Thread

How to do this dlookup?

 
 
G Lam
Guest
Posts: n/a
 
      4th Aug 2003
Hi, I have a little problem in a Dlookup statement.
If I wrote:
Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " & VarInFrmSlsOrd) It works
If I Wrote:
Dlookup("SlsOrdNbr", "TblOrd", "BoxNbr = " & VarInFrmBoxNbr) - It works
If I Wrote:
Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = SO1081 And BoxNbr = 3")
The SlsOrdNbr and BoxNbr are hard coded, but works.
If I wrote:
Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr =" &VarInFrmSlsOrd And "BoxNbr = "
& VarINFrmBoxNbr)
I got Type Mismatch error.
How can I do this right?
Thank you.
Gary


 
Reply With Quote
 
 
 
 
G Lam
Guest
Posts: n/a
 
      4th Aug 2003
I figured it out.
Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr =" &VarInFrmSlsOrd & "And BoxNbr =
"
& VarINFrmBoxNbr)
Fixed the problem
Gary
"G Lam" <(E-Mail Removed)> 秎ン
news:%(E-Mail Removed) い级糶...
> Hi, I have a little problem in a Dlookup statement.
> If I wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " & VarInFrmSlsOrd) It works
> If I Wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "BoxNbr = " & VarInFrmBoxNbr) - It works
> If I Wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = SO1081 And BoxNbr = 3")
> The SlsOrdNbr and BoxNbr are hard coded, but works.
> If I wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr =" &VarInFrmSlsOrd And "BoxNbr =

"
> & VarINFrmBoxNbr)
> I got Type Mismatch error.
> How can I do this right?
> Thank you.
> Gary
>
>



 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      4th Aug 2003
From your example, it looks as if SlsOrdNbr is a Text type field. You
therefore need quote marks as delimiters around the value for that field.
The And also needs to go inside the quotes.

Try:
Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = """ &
VarInFrmSlsOrd & """ And BoxNbr = " & VarINFrmBoxNbr)

More information on how to build the 3rd argument for DLookup():
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")

"G Lam" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi, I have a little problem in a Dlookup statement.
> If I wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " & VarInFrmSlsOrd) It works
> If I Wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "BoxNbr = " & VarInFrmBoxNbr) - It works
> If I Wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = SO1081 And BoxNbr = 3")
> The SlsOrdNbr and BoxNbr are hard coded, but works.
> If I wrote:
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr =" &VarInFrmSlsOrd And "BoxNbr =

"
> & VarINFrmBoxNbr)
> I got Type Mismatch error.
> How can I do this right?
> Thank you.
> Gary



 
Reply With Quote
 
G Lam
Guest
Posts: n/a
 
      4th Aug 2003
Allen,
Thank you.
Yes, the SlsOrdNbr field is a String field, while the BoxNbr field is a
Integer field.
I always wonder how and why these "s are added. I saw some examples, like
the one you did, had two or three " in a row. IN my case,
Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = """ &
VarInFrmSlsOrd & """ And BoxNbr = " & VarINFrmBoxNbr) -> won't work.
Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " &
> VarInFrmSlsOrd & " And BoxNbr = " & VarINFrmBoxNbr) -> Worked.

Gary


"Allen Browne" <(E-Mail Removed)> 秎ン
news:(E-Mail Removed) い级糶...
> From your example, it looks as if SlsOrdNbr is a Text type field. You
> therefore need quote marks as delimiters around the value for that field.
> The And also needs to go inside the quotes.
>
> Try:
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = """ &
> VarInFrmSlsOrd & """ And BoxNbr = " & VarINFrmBoxNbr)
>
> More information on how to build the 3rd argument for DLookup():
> Getting a value from a table: DLookup()
> at:
> http://allenbrowne.com/casu-07.html
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to the newsgroup. (Email address has spurious "_SpamTrap")
>
> "G Lam" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi, I have a little problem in a Dlookup statement.
> > If I wrote:
> > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " & VarInFrmSlsOrd) It works
> > If I Wrote:
> > Dlookup("SlsOrdNbr", "TblOrd", "BoxNbr = " & VarInFrmBoxNbr) - It works
> > If I Wrote:
> > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = SO1081 And BoxNbr = 3")
> > The SlsOrdNbr and BoxNbr are hard coded, but works.
> > If I wrote:
> > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr =" &VarInFrmSlsOrd And "BoxNbr

=
> "
> > & VarINFrmBoxNbr)
> > I got Type Mismatch error.
> > How can I do this right?
> > Thank you.
> > Gary

>
>



 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      4th Aug 2003
Text fields need the quote as a delimiter.

The string you need for the 3rd argument needs to contain quotes.
To indicate this is not the end of the string, embedded quotes must be
doubled in VBA, i.e. to get a string containing:
Surname = "O'Brien"
you must use:
"Surname = ""O'Brien"""
If the name were in a text box, you would need:
"Surname = """ & MyTextBox & """"
That's:
open quote
field name
equals
quote mark in the string must be doubled
closing quote
concetanate the value from the text box.
open quote
quote mark in the string must be doubled
closing quote

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")
"G Lam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Allen,
> Thank you.
> Yes, the SlsOrdNbr field is a String field, while the BoxNbr field is a
> Integer field.
> I always wonder how and why these "s are added. I saw some examples, like
> the one you did, had two or three " in a row. IN my case,
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = """ &
> VarInFrmSlsOrd & """ And BoxNbr = " & VarINFrmBoxNbr) -> won't work.
> Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " &
> > VarInFrmSlsOrd & " And BoxNbr = " & VarINFrmBoxNbr) -> Worked.

> Gary
>
>
> "Allen Browne" <(E-Mail Removed)> 秎ン
> news:(E-Mail Removed) い级糶...
> > From your example, it looks as if SlsOrdNbr is a Text type field. You
> > therefore need quote marks as delimiters around the value for that

field.
> > The And also needs to go inside the quotes.
> >
> > Try:
> > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = """ &
> > VarInFrmSlsOrd & """ And BoxNbr = " & VarINFrmBoxNbr)
> >
> > More information on how to build the 3rd argument for DLookup():
> > Getting a value from a table: DLookup()
> > at:
> > http://allenbrowne.com/casu-07.html
> >
> > --
> > Allen Browne - Microsoft MVP. Perth, Western Australia.
> > Tips for Access users - http://allenbrowne.com/tips.html
> > Reply to the newsgroup. (Email address has spurious "_SpamTrap")
> >
> > "G Lam" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > Hi, I have a little problem in a Dlookup statement.
> > > If I wrote:
> > > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " & VarInFrmSlsOrd) It

works
> > > If I Wrote:
> > > Dlookup("SlsOrdNbr", "TblOrd", "BoxNbr = " & VarInFrmBoxNbr) - It

works
> > > If I Wrote:
> > > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = SO1081 And BoxNbr = 3")
> > > The SlsOrdNbr and BoxNbr are hard coded, but works.
> > > If I wrote:
> > > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr =" &VarInFrmSlsOrd And

"BoxNbr
> =
> > "
> > > & VarINFrmBoxNbr)
> > > I got Type Mismatch error.
> > > How can I do this right?
> > > Thank you.
> > > Gary

> >
> >

>
>



 
Reply With Quote
 
G Lam
Guest
Posts: n/a
 
      4th Aug 2003
Allen,
Thank you. I will keep that in mind.
Gary
"Allen Browne" <(E-Mail Removed)> 秎ン
news:(E-Mail Removed) い级糶...
> Text fields need the quote as a delimiter.
>
> The string you need for the 3rd argument needs to contain quotes.
> To indicate this is not the end of the string, embedded quotes must be
> doubled in VBA, i.e. to get a string containing:
> Surname = "O'Brien"
> you must use:
> "Surname = ""O'Brien"""
> If the name were in a text box, you would need:
> "Surname = """ & MyTextBox & """"
> That's:
> open quote
> field name
> equals
> quote mark in the string must be doubled
> closing quote
> concetanate the value from the text box.
> open quote
> quote mark in the string must be doubled
> closing quote
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to the newsgroup. (Email address has spurious "_SpamTrap")
> "G Lam" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Allen,
> > Thank you.
> > Yes, the SlsOrdNbr field is a String field, while the BoxNbr field is a
> > Integer field.
> > I always wonder how and why these "s are added. I saw some examples,

like
> > the one you did, had two or three " in a row. IN my case,
> > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = """ &
> > VarInFrmSlsOrd & """ And BoxNbr = " & VarINFrmBoxNbr) -> won't work.
> > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " &
> > > VarInFrmSlsOrd & " And BoxNbr = " & VarINFrmBoxNbr) -> Worked.

> > Gary
> >
> >
> > "Allen Browne" <(E-Mail Removed)> 秎ン
> > news:(E-Mail Removed) い级糶...
> > > From your example, it looks as if SlsOrdNbr is a Text type field. You
> > > therefore need quote marks as delimiters around the value for that

> field.
> > > The And also needs to go inside the quotes.
> > >
> > > Try:
> > > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = """ &
> > > VarInFrmSlsOrd & """ And BoxNbr = " & VarINFrmBoxNbr)
> > >
> > > More information on how to build the 3rd argument for DLookup():
> > > Getting a value from a table: DLookup()
> > > at:
> > > http://allenbrowne.com/casu-07.html
> > >
> > > --
> > > Allen Browne - Microsoft MVP. Perth, Western Australia.
> > > Tips for Access users - http://allenbrowne.com/tips.html
> > > Reply to the newsgroup. (Email address has spurious "_SpamTrap")
> > >
> > > "G Lam" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > > Hi, I have a little problem in a Dlookup statement.
> > > > If I wrote:
> > > > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = " & VarInFrmSlsOrd) It

> works
> > > > If I Wrote:
> > > > Dlookup("SlsOrdNbr", "TblOrd", "BoxNbr = " & VarInFrmBoxNbr) - It

> works
> > > > If I Wrote:
> > > > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr = SO1081 And BoxNbr = 3")
> > > > The SlsOrdNbr and BoxNbr are hard coded, but works.
> > > > If I wrote:
> > > > Dlookup("SlsOrdNbr", "TblOrd", "SlsOrdNbr =" &VarInFrmSlsOrd And

> "BoxNbr
> > =
> > > "
> > > > & VarINFrmBoxNbr)
> > > > I got Type Mismatch error.
> > > > How can I do this right?
> > > > Thank you.
> > > > Gary
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dlookup using a date defiined by another dlookup =?Utf-8?B?QmVubnlESGlsbA==?= Microsoft Access VBA Modules 1 8th Aug 2007 02:56 AM
Help with DLookup lucky33 Microsoft Access Form Coding 3 16th Jul 2007 02:10 AM
Re: Dlookup function - copying the dlookup info into a field.... Douglas J. Steele Microsoft Access Forms 0 6th Dec 2006 03:05 PM
Using DLookUp =?Utf-8?B?QXJhY2E=?= Microsoft Access Queries 5 10th Jan 2005 09:01 PM
Dlookup problems (was my Dlookup hell) Kavvy Microsoft Access Form Coding 3 18th Nov 2003 01:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:57 AM.