Results 1 to 7 of 7
  1. #1
    tpcervelo is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    28

    Format in Dlookup function


    I am trying to populate a field on a form by concatinating two fileds from the first record of a table. I put the following in the fields Control Source.
    =DLookUp("[ShpOrdNbr] & '-' & [ShpOrdSuf]","SOKey","ID = 1")
    This works but the second field is a number and I would like to zero fill it so it shows as example 50553-003 instead of 50553-3. I tried to use the Format function but whatever I try as far as syntax causes an error.
    Any help is much appreciated.
    thanks...

  2. #2
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    Off the top of my head it sounds like you could use the Len function to check the length of the second field. If the result is 1 then concatonate "00" ; if the result is 2 the concatonate "0".

  3. #3
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    This is of course not a number. It is a text field that just doesn't use alpha characters.

    It is a little confusing because first you say 'it works' but then "would like to zero fill it so it shows as example 50553-003".....

    But if you are saying that you must convert say 3 to 003 in order to make it work then mj's advice is the correct idea to follow....

  4. #4
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    This code worked for me in a test DB:
    Code:
    =DLookUp("[ShpOrdNbr] & '-' & Format([ShpOrdSuf],'000')","SOKey","ID = 1")
    Table built under these assumptions:
    ShpOrdNbr - Number
    ShpOrdSuf - Number
    ID - Auto Number

  5. #5
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Sample attached

  6. #6
    tpcervelo is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    28

    Dlookup format

    thanks slave138...that worked. I thought I had tried encasing it in parens but obviously not.
    thanks again...

  7. #7
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    My pleasure

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

Similar Threads

  1. Replies: 3
    Last Post: 08-24-2010, 09:26 AM
  2. dlookup function problem
    By bdaniel in forum Programming
    Replies: 3
    Last Post: 04-26-2010, 05:55 AM
  3. Replies: 3
    Last Post: 10-06-2009, 02:11 PM
  4. I have Problem in processing Dlookup Function
    By Katada in forum Programming
    Replies: 2
    Last Post: 04-23-2006, 12:07 AM
  5. Need Help for Dlookup function
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 01-04-2006, 08:18 AM

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