Solved

Populate two date fields base on selection in combobox field

Posted on 2014-01-26
3
452 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 47

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 47

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

734 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