In Access, VB, I am needing help with a IF/THEN scenario involving dates.

Anonymous
2025-05-27T15:00:28+00:00

I have a form that I use for task scheduling and keeping track of dates when I performed that task. It is a simple form where I have a "STATUS" field combo box with "Not Started" and "Completed" for source options. Also, in the sourced table, I have columns identified for each of the four quarters in the year. I need help with the code that, if "STATUS" is selected "Completed", and today is, for example, is in the second quarter of this year, THEN enter "TODAYS DATE" in the "Quarter2" field.

Thanks,

Jeff Bomberger

Microsoft 365 and Office | Access | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2025-05-27T16:20:05+00:00

    I think you need something like

    DIM Q AS BYTE
    Q = DatePart("q", Date()) 
    
    If Q = 1 Then CompletedDate1 = Date() 
    If Q = 2 Then CompletedDate2 = Date() 
    If Q = 3 Then CompletedDate3 = Date() 
    If Q = 4 Then CompletedDate4 = Date()
    
    1 person found this answer helpful.
    0 comments No comments

11 additional answers

Sort by: Most helpful
  1. Anonymous
    2025-05-27T16:12:58+00:00

    Right now, I manually go in and change the code to save the data in the correct associated table field, "CompletedDate#" (1, 2, 3, or 4). Has to be a better way of doing it...

    Jeff

    0 comments No comments
  2. Anonymous
    2025-05-27T16:34:44+00:00

    Thanks! I added/modified my code to include your changes, and it seemed to work.

    Dim Q As Byte

    Q = DatePart("q", Date)

    If ([Status] = "Completed") And Q = 1 Then 
    
        [CompletedDate1] = Date 
    
    End If 
    
    If ([Status] = "Completed") And Q = 2 Then 
    
        [CompletedDate2] = Date 
    
    End If 
    
    If ([Status] = "Completed") And Q = 3 Then 
    
        [CompletedDate3] = Date 
    
    End If 
    
    If ([Status] = "Completed") And Q = 4 Then 
    
        [CompletedDate4] = Date 
    
    End If
    
    0 comments No comments
  3. George Hepworth 22,220 Reputation points Volunteer Moderator
    2025-05-27T16:46:35+00:00

    "I need to store multiple dates in the table is the reason for the 4 fields"

    Unfortunately, multiple date fields for the same data is an inappropriate table design for a relational database application.

    In turn, that table design forces you to adopt workarounds like this one to try to manage the data.

    You've been given a workaround that allows you to preserve that flawed table design, but that is not really the most appropriate way to handle it.

    These dates should be in a child table called something like "TaskCompletion".

    In that table you need one field for the foreign key to the task table, one field for the Quarter, and one field for the actual completion date.

    There are many excellent resources available on the internet to help you learn how to properly design tables for a relational database application. The process is called "Database Normalization", to distinguish it from other sorts of "normalization".

    You would probably benefit a lot from investing time to learn about Database Normalization and applying it to this project. Otherwise, the workarounds needed to manage inappropriately designed tables keep getting in the way of productivity.

    0 comments No comments
  4. Anonymous
    2025-05-27T17:11:20+00:00

    Thank you VERY much for the advice and I will indeed be visiting information on Database Normalization!!! This was a very simple task scheduling and completion database that I use, and it works, but not very efficiently.

    Jeff

    0 comments No comments