Results 1 to 9 of 9
  1. #1
    Steven.Allman is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2010
    Posts
    118

    Date Conversion through Update Query

    Long story as short as possible....
    I have created a very robust database the tracks employees with 'issues'
    Said database tracks hire date, contract termination date, pay grade, etc.. We also use it to do demographic data extrapolation and as I get request for this and that, it grows...
    I recently got permissions to the larger corporate personnel database, and have created a ‘update query’ that will pull from theirs, import the info to mine, and auto fill most of my form fields. What i am missing however is the DATE...The original database holds dates in ‘number fields’ as YYYYMMDD
    I utilize “date fields” in my database and wonder if there is something I can write in the SQL or design to have the update query convert the 20130129 to 29-JAN-13. The query is built and works, just need to figure out the conversion portion. I can post my code on here if needed, but due to information involved, I cannot post specifics about who, what I track...
    sorry



    Currently I use the LostFocus and some code to each field so when I tab through it does a proper case update, can I automatically set that to formclose and it update each field on the current record?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You should be able to use the DateSerial() function along with the Mid() function to pull out each appropriate portion.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    The following expression will do the required conversion:
    Format(Right([YourDateField],2) & "/" & Mid([YourDateField],5,2) & "/" & Left([YourDateField],4),"dd/mmm/yy")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    Quote Originally Posted by Bob Fitz View Post
    The following expression will do the required conversion:
    Format(Right([YourDateField],2) & "/" & Mid([YourDateField],5,2) & "/" & Left([YourDateField],4),"dd/mmm/yy")
    When throwing this into my query, it literally disappears upon saving.
    Format(Right([SIDPERS.PEBD],2) & "/" & Mid([SIDPERS.PEBD],5,2) & "/" & Left([SIDPERS.PEBD],4),"dd/mmm/yy")

    Here is the SQL from my update query
    Not sure where an expression would fit in here. This is my first forray into the expressions in a query that isnt simple "Age" or Date Range stuff..
    UPDATE [Positive People] INNER JOIN SIDPERS ON [Positive People].SSN = SIDPERS.SSN SET [Positive People].[Last] = [sidpers.last], [Positive People].[First] = [sidpers.first], [Positive People].Middle = [sidpers.Mi], [Positive People].UIC = [sidpers.uic], [Positive People].Grade = [sidpers.rank], [Positive People].Gender = [sidpers.sex], [Positive People].PEBD = [sidpers.pebd], [Positive People].DOB = [sidpers.dob], [Positive People].HOR_street = [sidpers.street], [Positive People].HOR_City = [sidpers.city], [Positive People].HOR_State = [sidpers.state], [Positive People].HOR_Zip = [sidpers.zip]
    WHERE ((([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn] And ([forms]![Positive people]![SSN])=[sidpers].[ssn]));
    Last edited by Steven.Allman; 01-30-2013 at 10:08 AM.

  5. #5
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    And I see how that works if I put that into an expression in my form, but the 1200 records i currently have I are already uzing the other format, so my issue is creating the Update Query that will take from
    SIDPERS:dob in format of ######## and put that in POSTIVE_PEOPLE:dob in DD-MMM-YY format
    is it possible to do this in a single query? Once I get this I can probably figure out the 30 other converstions I need, like grade, other dates, etc...

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Either should work fine in a query. What was the SQL of the query that failed? Or can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    Actually i got this to work like a charm!!! I was adding too much to the SQL, trying to make it do the import, THEN the conversion, instead of converting then importing.. This is sweet! Got the capitalization set up correctly and everything..
    now, LAST drama with this import...
    gender...
    BIG DADDY DATABASE says M and F
    Mine says Male and Female.
    Granted I could just alter mine, run an update and start using M and F, but can i set some string that converts like a ifwhen statement?

  8. #8
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    EVERYTHING WORKS!!!
    Thanks GUYS!!!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Glad you got it sorted out!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 8
    Last Post: 08-09-2012, 07:04 PM
  2. Date Conversion
    By mkc80 in forum Access
    Replies: 1
    Last Post: 06-27-2012, 04:04 PM
  3. Replies: 6
    Last Post: 06-14-2012, 03:39 PM
  4. query to update a date based on another date
    By tkendell in forum Access
    Replies: 3
    Last Post: 06-29-2011, 09:32 PM
  5. Access VBA - date format conversion
    By benattal in forum Programming
    Replies: 3
    Last Post: 12-22-2008, 10:40 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