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
367 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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

829 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