?
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
Medium Priority
?
386 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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 80 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

770 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