Results 1 to 12 of 12
  1. #1
    Chris1112 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    31

    Sorting by Date in non-Date Field

    I have a text box in which users sometimes place dates. The field is always Date/Time or something like "TBD". I know it's bad practice but I would like to be able to sort by date. When I use the following code, I get "data type mismatch." Is there a way to sort this field by date, then have the error fields sort after?



    Code:
        Me.OrderBy = "Year([2ndWalk]),Month([2ndWalk]),Day([2ndWalk])"
        Me.Refresh

  2. #2
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Try the code below set for when the form loads in On Open

    Me.OrderBy = [2ndWalk]
    Me.OrderByOn = True

  3. #3
    Chris1112 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    31
    Sadly this doesn't work. The dates are entered inconsistently. I know...I know. Day() Month() and Year() are still able to pull from the way they're entered. For instance, field values are "Apr 18 5:00 PM", "Apr 30", and "TBD". Sorting chronologically might be difficult.

  4. #4
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Well, it really sounds like you need to just add additional fields for times and if a record is "TBD". I would use a check box for "TBD" and set the other 2 fields to Date/Time and format how you want the info to look like after it is entered. Users can enter a date with just "4/30", and Access will understand it is "04/30/2012" or "Apr 30" or however you want it to look. It's not just bad practice to not save your dates in Date/Time - you will not be able to get the order results that you want due to the inconsistent data inputs.

  5. #5
    Chris1112 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    31
    Yeah, unfortunately the date format is not consistent for a reason. If conditional formatting would handle it, I could set it there but instead it has to be as it is or the users will rebel. They use specific and non-specific dates to show estimated, scheduled, or actual times.

    In any case, what I was hoping for was a qualifier to keep it from erroring when I pull Day() Month() and Year(). I suppose that would never work inside of a SortBy though. :\

  6. #6
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    It's not a conditional formatting deal. Once you create the field in the table, you set field to Date/Time and the format at the bottom in "Field Properties".

    There's no reason you couldn't have a Comments field next to the date so they can enter additional information, or perhaps you can create a Date/Time field for estimated, shceduled, or actual. I have all 3 fields ("Planned", "Forecast", and "Actual") in a few of my databases where I need to track and report all of the dates.

    There's really not much point to create a database where data will not be in a controlled environment. Might as well just stick to Excel.

  7. #7
    Chris1112 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    31
    Thanks for the help.

    This actually would be in Excel except that we require multiple users to utilize it. I suppose that I could create an unbound text box and update one of several fields based on what is put into that text box, then sort by them. I was hoping for something more straightforward.

  8. #8
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Straghtforward is controlling the field to Date/Time and allowing for comments outside of that field.

  9. #9
    Chris1112 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    31
    The issue is the specificity of the field. For instance, since dates are sometimes estimates as to the month, the day, or the specific time, how would you control the field to express that? For instance, if we estimate something to take place in November, the field would have the value "Nov 2012". If we have a scheduled time for that, it would be "November 2 08:15 AM". I wouldn't mind a date field, but if it always displays the time, it will be confusing as to what it represents, an estimate or an actual. This is where I wish I could use conditional formatting to change the Format from General Date to Short Date etc.

    Suggestions on how to handle this would be appreciated.

    Thanks

  10. #10
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Multiple fields - One for month, day, year, and time. Users would only fill in what they have estimates for. Concatenate month and year in a field on the form and order by the concatenated field then by day then by time. I would control month to a numeric field. To best control that, set the month to be a drop box linked to a table that has the month number and name and bind the number field after the month is selected.

  11. #11
    Chris1112 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    31
    Thanks for the help. This thread took a big turn and will be utterly useless to any who find it, but at least I should be fixed.

  12. #12
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    Well, if you're sorted, at least that much is accomplished!

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

Similar Threads

  1. Replies: 15
    Last Post: 04-06-2012, 10:57 AM
  2. Replies: 2
    Last Post: 03-31-2012, 07:53 AM
  3. Sorting by date
    By kaledev in forum Queries
    Replies: 2
    Last Post: 03-16-2011, 12:32 PM
  4. Date Sorting
    By sfoot0309 in forum Queries
    Replies: 1
    Last Post: 04-25-2010, 09:59 PM
  5. Sorting By Date!
    By Pirate in forum Access
    Replies: 0
    Last Post: 07-19-2007, 02:42 PM

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