Results 1 to 10 of 10
  1. #1
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188

    Weird date calculation help


    Hi all,
    I have a table lookup (tlkp_Category_Description) and in that table there are two fields called Category and Days. Each category has a corresponding amount of days. In my form I have the Category field based on that table lookup. Also in the form I have two date fields (Actual_Date and Expected_Date).

    What I need to do is create a calculation: when the user selects a category from the drop down in the form, the Expected_Date field will add the corresponding amount of days from the table lookup to the Actual_Date field and give me a date.

    Does that make sense? How could I do that?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Use DateAdd() ?
    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
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by Welshgasman View Post
    Use DateAdd() ?
    I got that much. I'm just not sure of the syntax of the days to add if it's not the record source for the form. It's stored in a table lookup

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    It does not matter where they come from as long as you have what you need, which would be the interval type, a start date and a number to add/subtract.
    Google the syntax.

    If you have to look it up in a table then look at DlookUp().
    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

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    It appears that you could get the number of days from the category combobox.
    The combobox rowsource should be "Select Category, Days from tlkp_Category_Description Order By Category;"
    Something like
    MyNewDate=Me.cboCategory.column(1)
    Last edited by davegri; 06-27-2024 at 02:30 PM. Reason: more

  6. #6
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by davegri View Post
    It appears that you could get the number of days from the category combobox.
    The combobox rowsource should be "Select Category, Days from tlkp_Category_Description Order By Category;"
    Something like
    MyDays=Me.cboCategory.column(1)

    Ok, I changed my form's query and got it working. I used =DateAdd("d",[MOSP_Days],[Actual_Submission_Date])

    However, now if the form has no data the field says #Type! How do I get the field to be blank until MOSP_Days and Actual_Submission_Date are both populated?

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Ok, I changed my form's query and got it working. I used =DateAdd("d",[MOSP_Days],[Actual_Submission_Date])

    However, now if the form has no data the field says #Type! How do I get the field to be blank until MOSP_Days and Actual_Submission_Date are both populated?
    I think you'll need VBA. In the after_update event of the combobox, you'll need to check if the proper date field is within the form textbox. If not, messagebox the user that the date needs to be filled in first.
    You'll need to remove the calculation from the form's textbox and move it to the after_update combobox event to populate the textbox.
    Sorry can't be more concise as I don't have information on your form controlnames.

  8. #8
    Join Date
    Jun 2022
    Posts
    28
    Maybe this?

    Code:
    =Nz(DateAdd("d",[MOSP_Days],[Actual_Submission_Date]),NULL)

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Probably need the NZ() around the date fields?
    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

  10. #10
    Join Date
    Jun 2022
    Posts
    28
    Quote Originally Posted by Welshgasman View Post
    Probably need the NZ() around the date fields?
    You're right, my bad.

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

Similar Threads

  1. Weird date re-format when exporting to Excel
    By matey56 in forum Reports
    Replies: 8
    Last Post: 09-08-2022, 05:02 PM
  2. import csv with weird date
    By Susy in forum Access
    Replies: 6
    Last Post: 04-28-2017, 12:02 PM
  3. Weird Age Calculation
    By tanyalee123 in forum Queries
    Replies: 4
    Last Post: 03-06-2015, 01:36 PM
  4. Replies: 2
    Last Post: 03-27-2012, 01:59 AM
  5. Date Paramater prints weird
    By NOTLguy in forum Reports
    Replies: 9
    Last Post: 10-20-2010, 07:58 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