Results 1 to 3 of 3
  1. #1
    JoeJr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    62

    Access VBA Code for Auto Populate date from select date plus combobox list critera

    Hello everyone,

    I have another question/issue that I am trying to figure out VBA code for. I have a DB that has two tables: DateTable and TypeForm. Datetable has "ID", "LastThruDate", "NextThruDate", "TypeofForm" (TypOfForm is a Combobox that referense data from TypeForm Table).

    TypeForm has "Title" which list Forms.

    I created a form based on the datetable to input LastThruDate and Select the Type of Form. What I am looking for is If I select Form1 from the list, I want it to auto populate a date based on LastThruDate + 365.

    on paper this is what I was looking at but just dont know how to write it in VBA when I open the form and for the dates to stay in the table:

    If Form1 is selected then "NextThruDate"="LastThuDate+365
    If Form2 is Selected then "NextThruDate"="LastThuDate+395
    If Form2 is Selected then "NextThruDate"=Date (Now)+30

    Attached is the DB.



    Thank you for all the help.

    DateIfThen.accdb

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You've got two calculations for 'Form2.'

    If Form2 is Selected then "NextThruDate"="LastThuDate+395
    If Form2 is Selected then "NextThruDate"=Date (Now)+30

    Is the last line supposed to be 'Form3?'

    Assuming this to be true...first you need to, in Form Design View

    1. Select the TypeOfForm Combobox
    2. Go to Properties - Data and make the Combobox Unbound by deleting its Control Source
    3. Go to Properties - Event
    4. Click on the AfterUpdate property to go to the code module
    5. Add the code below


    Code:
    Private Sub TypeOfForm_AfterUpdate()
    
    
    Select Case TypeOfForm
    
      Case 1 'Form1 selected
        
        Me.NextThruDate = DateAdd("d", 365, Me.LastThruDate)
        
      Case 2 'Form2 selected
      
       Me.NextThruDate = DateAdd("d", 395, Me.LastThruDate)
      
      Case 3 'Form3 selected
     
      Me.NextThruDate = DateAdd("d", 30, Me.LastThruDate)
    
    End Select
    
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    JoeJr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    62
    Quote Originally Posted by Missinglinq View Post
    You've got two calculations for 'Form2.'

    If Form2 is Selected then "NextThruDate"="LastThuDate+395
    If Form2 is Selected then "NextThruDate"=Date (Now)+30

    Is the last line supposed to be 'Form3?'

    Assuming this to be true...first you need to, in Form Design View

    1. Select the TypeOfForm Combobox
    2. Go to Properties - Data and make the Combobox Unbound by deleting its Control Source
    3. Go to Properties - Event
    4. Click on the AfterUpdate property to go to the code module
    5. Add the code below


    Code:
    Private Sub TypeOfForm_AfterUpdate()
    
    
    Select Case TypeOfForm
    
      Case 1 'Form1 selected
        
        Me.NextThruDate = DateAdd("d", 365, Me.LastThruDate)
        
      Case 2 'Form2 selected
      
       Me.NextThruDate = DateAdd("d", 395, Me.LastThruDate)
      
      Case 3 'Form3 selected
     
      Me.NextThruDate = DateAdd("d", 30, Me.LastThruDate)
    
    End Select
    
    End Sub

    Linq ;0)>

    Thank you. It works great but the only issue that I am having with it is Form3 should be date now + 30 days. I tried entering in:

    me.NextThruDate=(Date(now)+30) but it didnt work.

    Edit: I fixed it and got it to work lol. Thank you for your help

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

Similar Threads

  1. Replies: 2
    Last Post: 01-27-2015, 06:12 PM
  2. Replies: 1
    Last Post: 08-05-2014, 12:40 PM
  3. Auto populate text from date
    By losingmymind in forum Access
    Replies: 4
    Last Post: 05-30-2013, 10:39 AM
  4. Replies: 7
    Last Post: 11-28-2012, 01:41 PM
  5. Auto populate date field in payment table
    By jeffrey.ccs in forum Access
    Replies: 4
    Last Post: 11-08-2012, 04:44 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