Solved

Populate two date fields base on selection in combobox field

Posted on 2014-01-26
3
454 Views
Last Modified: 2014-01-29
I have three fields on a form.

Field #1 is a combobox from which a user can select a year.  For example, "2014"

Fields #2 and #3 are fields which I want to populate on the afterupdate event of field #1.

If the user selected 2014 from field #1, I want field #2 to populate with "7/1/2013"  (It will always be July 1st).

and

If the user selected 2014 from field #1, I want field #3 to populate with "6/30/2014"  (one year after field #2).

How can this be done?  (This is similar to a question answered previously by an expert but the combobox selection is different)
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 39810448
Sure, the combo boxes afterUdate event would look like:

Private Sub cbo_Year_AfterUpdate

   me.field2 = DateSerial(Val(me.cbo_Year) - 1, 7, 1)
   me.field3 = DateSerial(val(me.cbo_Year), 6, 30)

End Sub
0
 

Author Comment

by:SteveL13
ID: 39810456
Getting error... wrong number of arguments.

Here is the code with real field names:

    Me.txtStartDate = DateSerial(Val(Me.cboSelectYear, -1, 7, 1))
    Me.txtEndDate = DateSerial(Val(Me.cboSelectYear, 6, 30))

(I had to add ) to end if each line)
0
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39810561
You put the closing ) of the VAL ( ) function in the wrong place.  It should have gone immediately after the cboSelectYear combo box reference.  This ensures that the value in your combo is interpreted as a number.

    Me.txtStartDate = DateSerial(Val(Me.cboSelectYear) -1, 7, 1)
    Me.txtEndDate = DateSerial(Val(Me.cboSelectYear), 6, 30)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question