Results 1 to 5 of 5
  1. #1
    decimal48 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    8

    Question Setting the formatting of dlookup fields

    Having a weird problem. I have a query and one column is populated by a dlookup command. It grabs the price of something (formatted in currency) from a table, and outputs it to my query. I'm making a report based on this query and I just cannot get it to output it as a currency. The values are also left aligned which I recall reading somewhere meant that the data might be coming through as text instead of numbers?
    I tried copying and pasting "$#,##0.00;($#,##0.00)" from the format property of one of my currency fields into the dlookup fields but it did not work.

    Anyone have any insight?



    edit: Actually this may be more of a query issue then. I cant set the format of the dlookup column in design view of the origin query. The dropdown menu is just blank. And also the data is left aligned in those columns as well. I'm guessing if I fix that issue, I fix the report issue.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Format returns a string.
    Use the format of the control in your report.

    Unless you are using multiple criteria, probably better to join tables for the price.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Maybe use Val() function to convert DLookup result back to number.

    When you say "field", do you mean textbox?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    decimal48 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    8
    How would I package that line? val(dlookup())? Are there any other operators I need to throw in with val?

    edit: yes that worked! I packaged the line as I wrote above, and now I can select currency as a format. Thanks!

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Others have said that DLookups in a query don't make a whole lot of sense (partly because they're inefficient), and I tend to agree with them. If you can't include the needed table in the query, there might be something wrong with the relationships. If using it anyway, you should make sure the value it returns is unique else it will return the first occurrence and that might be incorrect. A query would reveal this since your record count would be more than you expect. If you intend to use a query with DLookup as a source for an append or update query, you'd also want to ensure the target field will accept null in case the lookup returns null (if it is to be appended/updated), or be sure it never will.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-14-2018, 07:58 AM
  2. Setting Criteria for one of 3 related fields
    By dmelsass in forum Access
    Replies: 9
    Last Post: 08-29-2017, 08:28 AM
  3. Replies: 1
    Last Post: 06-06-2014, 08:26 AM
  4. Setting User Permissions using Dlookup
    By RachelBedi in forum Programming
    Replies: 1
    Last Post: 10-18-2012, 08:36 AM
  5. Setting fields visible/invisible
    By col5473 in forum Forms
    Replies: 1
    Last Post: 09-17-2010, 09:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums