473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Add records on days selected by checkbox between date range

Hello,

I have a database which manages bookings for casual staff. When bookings are for just one day, then they can be entered as a new record into a form. Frequently however, a booking may be for a staff member to attend every week day for several weeks. Rather than enter each shift in individually I have a form which allows the user to enter dates and shift times, and then hit a button which runs some code (that people from the scripts helped me with - thank you) that adds a record for each weekday between the start and end date. This code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Weekdays_Click()
  2.  
  3. DoCmd.SetWarnings False
  4.  
  5. Dim dteIterator As Date
  6. dteIterator = Me!StartDate
  7. Do While dteIterator <= Me!EndDate
  8. If Weekday(dteIterator, vbSunday) <> vbSaturday And _
  9. Weekday(dteIterator, vbSunday) <> vbSunday Then
  10.     DoCmd.RunSQL "INSERT INTO tblshifts(ShiftDate, Shiftbookedby, Shiftbookeddate, Shiftbookedtime, shiftclid, shiftstart, shiftend, shiftbreaks, shiftactstart, shiftactend, shiftactbreaks, shiftmargin, shiftrole, shiftspecialrate, shiftnotes, shiftstatus) VALUES (#" & Format(dteIterator, "mm/dd/yyyy") & "#, ' " & Me![BookedBy] & " ', #" & Format(Me!BookedOn, "mm/dd/yyyy") & "#, #" & Format(Me!BookedTime, "hh:mm") & "#, ' " & Me!Centre & " ', #" & Format(Me!StartTime, "hh:mm") & "#, #" & Format(Me!EndTime, "hh:mm") & "#, ' " & Me!Breaks & " ', #" & Format(Me!StartTime, "hh:mm") & "#, #" & Format(Me!EndTime, "hh:mm") & "#, ' " & Me!Breaks & " ', ' " & Me!Margin & " ', ' " & Me!Role & " ', ' " & Me!SpecialRate & " ', ' " & Me!Notes & " ', 1);"
  11. End If
  12. dteIterator = DateAdd("d", 1, dteIterator)
  13. Loop
  14.  
  15. DoCmd.SetWarnings True
  16.  
  17. MsgBox "Your shifts have been added!"
  18.  
  19. DoCmd.Close
  20.  
  21. End Sub
  22.  
This all works fine. My new issue is that sometimes shifts repeat but they aren't every weekday - say for example a shift repeats on Monday and Wednesday for a number of weeks. What I would like to do is add to the form a check box for each day of the week, and then, when the user clicks the button, for the code to run adding shifts for the days selected between the two dates. I'm guessing this will involve altering the above code with some If and Else Ifs but I'm not quite sure how to put it all together.

Any help or suggestions would be greatly appreciated.
Jan 7 '08 #1
1 2694
zaidlig
45
Hello,

I have a database which manages bookings for casual staff. When bookings are for just one day, then they can be entered as a new record into a form. Frequently however, a booking may be for a staff member to attend every week day for several weeks. Rather than enter each shift in individually I have a form which allows the user to enter dates and shift times, and then hit a button which runs some code (that people from the scripts helped me with - thank you) that adds a record for each weekday between the start and end date. This code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Weekdays_Click()
  2.  
  3. DoCmd.SetWarnings False
  4.  
  5. Dim dteIterator As Date
  6. dteIterator = Me!StartDate
  7. Do While dteIterator <= Me!EndDate
  8. If Weekday(dteIterator, vbSunday) <> vbSaturday And _
  9. Weekday(dteIterator, vbSunday) <> vbSunday Then
  10.     DoCmd.RunSQL "INSERT INTO tblshifts(ShiftDate, Shiftbookedby, Shiftbookeddate, Shiftbookedtime, shiftclid, shiftstart, shiftend, shiftbreaks, shiftactstart, shiftactend, shiftactbreaks, shiftmargin, shiftrole, shiftspecialrate, shiftnotes, shiftstatus) VALUES (#" & Format(dteIterator, "mm/dd/yyyy") & "#, ' " & Me![BookedBy] & " ', #" & Format(Me!BookedOn, "mm/dd/yyyy") & "#, #" & Format(Me!BookedTime, "hh:mm") & "#, ' " & Me!Centre & " ', #" & Format(Me!StartTime, "hh:mm") & "#, #" & Format(Me!EndTime, "hh:mm") & "#, ' " & Me!Breaks & " ', #" & Format(Me!StartTime, "hh:mm") & "#, #" & Format(Me!EndTime, "hh:mm") & "#, ' " & Me!Breaks & " ', ' " & Me!Margin & " ', ' " & Me!Role & " ', ' " & Me!SpecialRate & " ', ' " & Me!Notes & " ', 1);"
  11. End If
  12. dteIterator = DateAdd("d", 1, dteIterator)
  13. Loop
  14.  
  15. DoCmd.SetWarnings True
  16.  
  17. MsgBox "Your shifts have been added!"
  18.  
  19. DoCmd.Close
  20.  
  21. End Sub
  22.  
This all works fine. My new issue is that sometimes shifts repeat but they aren't every weekday - say for example a shift repeats on Monday and Wednesday for a number of weeks. What I would like to do is add to the form a check box for each day of the week, and then, when the user clicks the button, for the code to run adding shifts for the days selected between the two dates. I'm guessing this will involve altering the above code with some If and Else Ifs but I'm not quite sure how to put it all together.

Any help or suggestions would be greatly appreciated.
Actually this would be a simple change just add a check to the lines 8 and 9 in your code to verify which days are checked on the form. Currently you check to make sure the day you are looping through is not Saturday or Sunday - just expand the check to include the new check boxes on on your form (Mon - Fri).
Jan 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: David Mitchell | last post by:
I have tried using the following code to count the specific number of each weekday but get a compile error "User defined type not defined" which I think relates to the first line of the function: -...
2
by: Terry | last post by:
I have a database that I would like to query for a specific date range. I want to create a report based on this query that will pull any records from the last 7 days. Is this possible? Can...
7
by: GJPeacock | last post by:
Hi all, Please excuse my limited technical knowledge of PHP, so far i have only created PHP sites using Dreamweaver, i find know that i need features outside of it's capabilities. I am trying...
2
by: Carl | last post by:
Hi, I have a query that produces an output similar to the sample shown below. These records are based on certain criteria and a date range selected from a form. I need to create some kind of...
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
2
by: miguelleugim | last post by:
I need to SUM a range of records from a fixed DATE in the DB, the fixed date is 'A.relationship_from' and I have to SUM 90 days from that DATE SELECT A.AGENT_CODE,T.AGENT_ID,Count...
14
by: David | last post by:
Hi, I have a form on which a user can select a checkbox against a record. Each checkbox carries the RecordID of a product. ---------------------------------------------------------------- I...
1
by: RussCRM | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.