DateAdd Function

I am using the Date Add function to add hours to calculate an end time based on the start time entered on a form. I have hard coded a number (default is currently 2) as the increment so the function works, but what I really want to do is give the user an option to select a default increment that would be displayed in a control on a form. Is there any way to do this?
This is the code that I am currently using
Private Sub cboMondayStart_AfterUpdate()
Me.cboMondayEnd = DateAdd("h", 2, Me.cboMondayStart)
End Sub

Open in new window

Harry BattDirector of DevelopmentAsked:
Who is Participating?
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
add a textbox "txtIncrement" to your form

Private Sub cboMondayStart_AfterUpdate()

if me.txtIncrement & ""<>"" then

Me.cboMondayEnd = DateAdd("h", me.txtIncrement, Me.cboMondayStart)

      msgbox "Enter increment!"
      exit sub

end if

End Sub

or add a listbox/combobox with list of increment that the user can choose from

Dale FyeCommented:
You might want to take a look at my article on command bars ( part 2).  In the attached database.  There is an example of using a shortcut menu to store values.

Sent from iphone
Harry BattDirector of DevelopmentAuthor Commented:
Thank you for your solution. I created a combo box with 1-12 values and it works perfectly. I also like that you set the focus to the cboIncrement control.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.