Results 1 to 13 of 13
  1. #1
    tanyalee123 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    51

    Question What's wrong with my expression/query??

    Hi all!


    So this is what I'm trying to accomplish. I have a spreadsheet that I imported into my DB (termdate) because I need to update the TERMDATE of an existing table (BH_Visit). Problem is that the spreadsheet I imported has a different format for the date. The spreadsheet presents the date in YYYYMMDD and I need MM/DD/YYYY. So I created an update query that looks like this. When I try to run it, Access tell me that my expression isn't valid. I've used this expression many times before because we have many dates that do not match our database. Can anyone see what I'm doing wrong, and do I have my query set up correctly? Thank you in advance for any assistance!!
    (Field2 is the date)

    Click image for larger version. 

Name:	query.jpg 
Views:	17 
Size:	28.5 KB 
ID:	18263

  2. #2
    Xarkath is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Millcreek WA
    Posts
    92
    Hello,

    My guess is that it does not like the the Left and Right joined in such a way. Instead try "mid()". Mid([termdate].[Field2],5,2). That should result in the mm.

    So TermDate: Mid([termdate].[Field2],5,2) & "/" & Right(([termdate].[Field2],2) & "/" & Left([termdate].[Field2],4) should get the results you are looking for. However, I have not tested this.


  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Edit: Oops. I missed the table name "TermDate". A table name "TermDate" and a field named "TermDate".... confusing


    "Field:" means what field are you trying to update?
    "Update To" is what you want to the above field to?

    So you should have;
    Code:
    "Field:" TermDate
    "Table:" BH_Visit
    "Update To:" Left(Right([Field2],4),2) & "/" & Right([Field2],2) & "/" & Left([Field2],4)
    "Criteria:" Is Null
    But even that formula is weird. If "Field2" is a text field and "TermDate" is a Date/Time field, I would use:

    Code:
    DateSerial(Left([Field2],4), Mid(Field2,5,2), Right(Field2,2))
    If "TermDate" is a text field, I would use:
    Code:
    Mid(Field2,5,2) & "/" & Right(Field2,2) & "/" & Left([Field2],4)

  4. #4
    tanyalee123 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    51
    Thank you so much for your help; I am trying this suggestion but it's saying it missing a bracket or parenthesis or vertical bar...I can't see what might be missing; any idea?

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I missed an ampersand when I typed in your expression. Should be
    Code:
    "Field:" TermDate
    "Table:" BH_Visit
    "Update To:" Left(Right([Field2],4),2) & "/" & Right([Field2],2) & "/" & Left([Field2],4)
    "Criteria:" Is Null

  6. #6
    tanyalee123 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    51
    Thank you everyone, those expressions are working, except when I run it, I am getting the message that there is a conversion failure, so it's not updating the field. I re-imported the spreadsheet and chose "date/time" for the field format. The field format for TermDate is also date/time, so why would there be a conversion failure? Does anyone have any ideas?

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Can you post your dB?

  8. #8
    tanyalee123 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    51
    I wish I could, but it's patient data.

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Doesn't have to be real data. Just a few records to be able to test.

    The code works for me, but I created the two tables & test data.
    Would need to see how the spreadsheet data is imported into Access.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Make copy and remove/replace sensitive info (LastName, address, phone, email, ssn)
    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.

  11. #11
    tanyalee123 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    51
    OK I deleted pretty much everything and kept 4 fake people....but what the heck, am I blind, I can't see the attach option, just insert image, link, etc...

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Click Go Advanced below the Quick Reply editor. The Attachment Manager is below the Advanced Post Editor window.
    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.

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Be sure and read the first line in June's signature (bottom of her posts).

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

Similar Threads

  1. What is wrong with this expression
    By azhar2006 in forum Reports
    Replies: 3
    Last Post: 07-31-2014, 10:17 AM
  2. Replies: 7
    Last Post: 08-13-2013, 11:03 PM
  3. What's wrong with this expression in a query?
    By djclntn in forum Queries
    Replies: 18
    Last Post: 11-17-2011, 06:12 PM
  4. Expression gives wrong results
    By newtoAccess in forum Queries
    Replies: 22
    Last Post: 12-03-2010, 12:21 AM
  5. What's wrong with this expression
    By tallroger in forum Access
    Replies: 1
    Last Post: 05-05-2009, 04:00 PM

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