?
Solved

Date scheduling

Posted on 2014-12-10
2
Medium Priority
?
106 Views
Last Modified: 2014-12-11
I have a form with the following fields:

Date of Last Visit (date field) named "txtDateOfPreviousVisit"
Visit Start Date (date field) named "txtStartDate"
Visit Frequency (number field) named "txtVisitFrequency"
Day of Week (number field) named "txtDayOfWeek"

When the form opens I want "txtStartDate" to populate with "txtDateOfPreviousVisit" + "txtVisitFrequency""

BUT...

If "txtDayOfWeek" is for example, 3 (which is Tuesday) then the "txtStartDate" has to be a Tuesday also but never past the "txtVisitFrequency" value.

If the date doesn't land on that day of the week then it has to be the correct day of the week prior to "txtDateOfPreviousVisit" + "txtVisitFrequency".

In other words, for example, if txtDateOfPreviousVisit is 12/9/2014 and txtDayOfWeek is 3 (Tuesday), and txtVisitFrequency is 90 then txtStartDate has to be 3/3/2015, not 3/9/2014 because that is a Monday.

Very complicated I know.  I sure hope someone can help.
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 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 40492735
This small chunk of code will get you started. Replace the hardcoded values for lastVisit, frequency, dayOfWeek with the values from your application and give it a go:
Private Sub Form_Load()
    Dim lastVisit As Date
    Dim startDate As Date
    Dim frequency, dayOfWeek As Integer
    
    lastVisit = #10/11/2014#
    frequency = 90
    dayOfWeek = 3
    
    startDate = lastVisit + frequency
    While DatePart("w", startDate) <> dayOfWeek
        startDate = startDate - 1
    Wend
    
End Sub

Open in new window

0
 

Author Comment

by:SteveL13
ID: 40494089
Perfect.  Thank you very much.
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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

765 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