?
Solved

create and update field date, and perform increment to 1

Posted on 2013-05-20
11
Medium Priority
?
493 Views
Last Modified: 2013-06-14
Hi,
I have attached access file, I need help out in doing the following:

I have table1 with 2 fields ,

batch      batchDate

Batch      BatchDate
1             20/05/2013
2      
3      
4      
5      
6      
7      
8      
9      
10      
11      
12      
13      
14

I need to click in a form button control that can increment automatically the field BatchDate with 1 for the next record starting from 20/05/2013,and SKIP weekends (friday and saturday) the result should be :

Batch      BatchDate
1             20/05/2013
2             21/05/2013
3             22/05/2013
4             23/05/2013
5             26/05/2013  'SKIP 24/05/2013 and 25/05/2013 (vbfriday , vbsatuday) weekend
6             27/05/2013
7             28/05/2013
8             29/05/2013
9             30/05/2013
10             02/06/2013 'SKIP 31/05/2013 and 01/06/2013 (vbfriday , vbsatuday-weekend)
11             03/06/2013
12             04/06/2013
13             05/06/2013
14           06/06/2013

the next thing if it possible to help out with , is that when i choose a record in the form (attached file), for example 7      28/05/2013 , and change the date manually to 29/05/2013
and click another button , it will increment all next dates from this record with one, and keep SKIPPING the weekend days, the result should be:

6             27/05/2013
7             29/05/2013
8             30/05/2013
9             02/06/2013 'SKIP 31/05/2013 and 01/06/2013 (vbfriday , vbsatuday-weekend)
10             03/06/2013
11             04/06/2013
12             05/06/2013
13             06/06/2013
14           07/06/2013
Database1.accdb
0
Comment
Question by:drtopserv
[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
  • 5
  • 4
11 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 2000 total points
ID: 39183277
Adding this bit of code to your command button should solve both problems:
    Dim rst As Recordset
    Dim dt As Date
    
    Set rst = Me.RecordsetClone
    rst.Bookmark = Me.Bookmark
    dt = rst!BatchDate
    rst.MoveNext
    
    Do While Not rst.EOF
        dt = dt + Switch(Weekday(dt) = vbFriday, 3, Weekday(dt) = vbSaturday, 2, True, 1)
        rst.Edit
        rst!BatchDate = dt
        rst.Update
        rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing

Open in new window

0
 

Author Comment

by:drtopserv
ID: 39183434
seems need small tweak , it doesn`t skip friday and saturday, BUT saturday and sunday instead!
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39183452
Oops, I misread your requirements. Just change vbFriday to vbThursday and vbSaturday to vbFriday.
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 

Author Comment

by:drtopserv
ID: 39183461
what is that swtich function do ?
and that 3,2,1 number in it?
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39184317
Switch (condition1, value1, condition2, value2, etc...)
The Switch function looks for the first condition in your list of arguments that is true and returns the value after it.  In the code I gave, if the day is Thursday it returns the number 3,  if Friday, the number 2, otherwise it returns a 1 because the 3rd condition evaluates to True.
Adding 3 days to Thursday's date gives you Sunday. The same happens with adding 2 days to Friday's date.
0
 

Author Comment

by:drtopserv
ID: 39190395
thnx alot, i tried your code, it work only when first date in there, it adds date to next record skipping friday and sat.
but the problem is , when i get into a form and try to change specific date and need your code to loop to next records and change dates it doesn`t work.
i had to reopen the form again and click the button again when the first record in there
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39190409
I don't follow. Are you talking about when you change the date in a layer record? Are you still in that same record after you change the date? I noticed in your sample that after changing the date it goes to the next record. You need to revise the Tab Order so that it stays on the same record before you click the button.
0
 

Author Comment

by:drtopserv
ID: 39190417
oh found where is the problem
i should have to save record before run the code :}
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39247919
I've requested that this question be closed as follows:

Accepted answer: 500 points for IrogSinta's comment #a39183277

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Closing Comment

by:drtopserv
ID: 39247920
Perfect answer!!!, thnx alot Man!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

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