Solved

Populate two date fields base on selection in combobox field

Posted on 2014-01-26
3
444 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
  • 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now