?
Solved

Populate two date fields base on selection in combobox field

Posted on 2014-01-26
3
Medium Priority
?
456 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
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 earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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