Solved

Populate two date fields base on selection in combobox field

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

810 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