Solved

Can I type the Dlookup function in the ControlSource property of a text box on a form or report?

Posted on 2004-08-05
15
381 Views
Last Modified: 2008-02-01
Hello
 
My question is:

Can I type the Dlookup function in the ControlSource property of a text box on a form or report?
Acctually, I want to poll Price from table named "Stock",so I will have Dlookup formula that looks like this:

=DLookup("[Price]", Stock", "[ItemNumber]like" & "'" & [ItemNumber] & "'")

This formula works great in Microsoft visual basic, but when I try to type it in ControlSource
 of a text box,syntax erros appears.

Any help is appreciated.

Thanks
0
Comment
Question by:adnan2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 11

Expert Comment

by:phileoca
ID: 11731093
yes, although on my reports, i think i put it in labels.
0
 
LVL 11

Expert Comment

by:phileoca
ID: 11731131
nm, i do it in textboxes.  and yes, in the control source.
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 11731151
Your problem is SYNTAX...

DLookup("[Price]", Stock", "[ItemNumber] Like " & "'" & [ItemNumber] & "*'")
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:morpheus30
ID: 11731156
Sorry...

DLookup("[Price]", "Stock", "[ItemNumber] Like " & "'" & [ItemNumber] & "*'")
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 11731167
I don't know if you want the wild character or not, but that's usually why I would use the LIKE operator instead of the equal ("=") operator.
0
 
LVL 11

Expert Comment

by:phileoca
ID: 11731175
this is what i have on my report:
locMondayDate = DLookup("MondayDate", "HistoryWeeks", "[ID] = " & ScheduleWeek1)

yours appears to be syntax error. too many &'s
=DLookup("[Price]", Stock", "[ItemNumber]Like" & "'" & [ItemNumber] & "'")

if ItemNumber is a text field, use single quotes.
=DLookup("[Price]", Stock", "[ItemNumber] = '" & [ItemNumber] & "'")

if ItemNumber is a Number Field, you don't need single quotes.
=DLookup("[Price]", Stock", "[ItemNumber] =" & [ItemNumber])
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 11731183
Oh, I saw something else too...

DLookup("[Price]", "Stock", "[ItemNumber] Like " & "'" & Me.[ItemNumber] & "*'")
0
 

Author Comment

by:adnan2004
ID: 11737310
Thnx for help.

When I try to type formulas you suggested:

=DLookup("[Price]", Stock", "[ItemNumber] = '" & [ItemNumber] & "'")
And
=DLookup("[Price]", "Stock", "[ItemNumber] Like " & "'" & Me.[ItemNumber] & "*'")

 in Control source of text box, i get erorr message:

"You omitted an operand or operator, you entered an invalid character or comma,
 or you entered text without surrounding quotation marks."

Price is Number and ItemNumber is Text.
I try it all, but it still doesnt work!
0
 
LVL 11

Accepted Solution

by:
phileoca earned 20 total points
ID: 11737363
=DLookup("[Price]", Stock", "[ItemNumber] = '" & [ItemNumber] & "'")
missing a quote at stock.  try this:

=DLookup("[Price]", "Stock", "[ItemNumber] = '" & [ItemNumber] & "'")
0
 

Author Comment

by:adnan2004
ID: 11737673
I try that also...
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 11737760
Did you try this?

=DLookup("Price", "Stock", "ItemNumber = '" & Me.[ItemNumber] & "'")
0
 
LVL 12

Expert Comment

by:Sayedaziz
ID: 11742315
slight modification:
=DLookup("Price", "Stock", "ItemNumber = " & Forms!Formname!ItemNumber )
0
 

Author Comment

by:adnan2004
ID: 11743372
I think I have find solution:

=DLookup("[Price]"; Stock"; "[ItemNumber]like" & "'" & [ItemNumber] & "'")

As you can see only modification i made is changing "," in to ";" in Controul source of tex box, and it works perfect.

Thanks for helping me out.

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question