Solved

Date scheduling

Posted on 2014-12-10
2
104 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
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
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.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

749 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