Results 1 to 8 of 8
  1. #1
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    44

    Syntax for using "Left" to select part of a field as a Control Source for a report

    I have an Access report that the Record Source query includes a field called "dates" containing a Short Text-format field whose values are, for example, dates that are 8 characters long, i.e: "09/07/24".


    I want to display the only the 5 characters, i.e: "09/07"
    In the Control Source for the field I have =Left$([dates],5)
    I know I don't have the correct syntax.
    Click image for larger version. 

Name:	Screenshot (1).png 
Views:	18 
Size:	164.7 KB 
ID:	52259

    Bud
    Attached Thumbnails Attached Thumbnails Screenshot (1).jpg   Screenshot (1).jpg  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Why are you pasting 3 pictures which are the same?
    Dates should be held as Dates and they are really numeric. It is the formatting that you see.

    However I have just tested
    Code:
    ? left(date,5)
    30/09
    in the immediate window and that works, so I have learnt something new today.

    You could just as easy have a format of "mm/dd" or "dd/mm" depending on where you live? on that control, which would probably be my choice.
    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
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I'm on the fence with the date thing in this case, given that to get something like "09/30" you'd have to use Format(), in which case it will turn it into a string anyway. If the posted info is the only use for these dates I'm not sure it matters. You wouldn't be able to use DatePart on valid dates either, unless you'd be OK with single characters for month and day values less than 10.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    44
    Could not figure out how to delete the extra photos, sorry.
    The field in the table is defined as Small Text, not date.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What makes you think your syntax is not correct?

    Why are dates saved as text?
    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.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by Micron View Post
    I'm on the fence with the date thing in this case, given that to get something like "09/30" you'd have to use Format(), in which case it will turn it into a string anyway. If the posted info is the only use for these dates I'm not sure it matters. You wouldn't be able to use DatePart on valid dates either, unless you'd be OK with single characters for month and day values less than 10.
    @Micron, No I was thinking of the Format property of the control?
    I believe that does not convert the value to a string?
    I tried it on a date control of mine, but did not test to see if it became a string. How would one do that?
    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

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I'd use the immediate window.
    ?Typename(controlnamehere.Value). This is one of the few places you need .Value
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by Micron View Post
    I'd use the immediate window.
    ?Typename(controlnamehere.Value). This is one of the few places you need .Value
    ? Typename(Forms!frmDailyEntry!sfcsfrmdaily.form.txt dailydate.Value)
    Date

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

Similar Threads

  1. Replies: 7
    Last Post: 03-19-2021, 05:54 PM
  2. Replies: 3
    Last Post: 02-19-2016, 04:34 PM
  3. Part of field matches part of another field
    By fishhead in forum Queries
    Replies: 13
    Last Post: 04-10-2015, 01:54 PM
  4. Replies: 3
    Last Post: 09-02-2013, 12:58 PM
  5. Replies: 1
    Last Post: 10-08-2012, 09:01 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