I gained a ton of knowledge from an older post by ADezii - and for that I thank you !!! However, I need to take it a step further. I need to add dates and numerous times to my table. I can get it to add one time per date - but I need all the times for every date. For example, this is what I get now: - DoseDate DoseTime
-
9/18/2013 8:00 AM
-
9/19/2013 9:00 AM
-
9/20/2013 10:00 AM
-
9/21/2013 11:00 AM
-
9/22/2013 12:00 PM
-
9/23/2013 1:00 PM
-
9/24/2013 2:00 PM
-
9/25/2013 3:00 PM
-
9/26/2013 4:00 PM
-
9/27/2013 5:00 PM
-
9/28/2013 6:00 PM
-
9/29/2013 7:00 PM
-
9/30/2013 8:00 PM
-
10/1/2013 9:00 PM
-
10/2/2013 10:00 PM
-
9/10/2013 8:00 AM
-
9/11/2013 9:00 AM
-
9/12/2013 10:00 AM
-
9/13/2013 11:00 AM
-
9/14/2013 12:00 PM
-
9/15/2013 1:00 PM
-
9/16/2013 2:00 PM
-
9/17/2013 3:00 PM
-
9/18/2013 4:00 PM
-
9/19/2013 5:00 PM
-
9/20/2013 6:00 PM
-
9/21/2013 7:00 PM
-
9/22/2013 8:00 PM
-
9/23/2013 9:00 PM
-
9/24/2013 10:00 PM
But I need: 9/17 8:00 a.m. 9/17 9:00 a.m. etc. Here is my (Your) code: - Dim MyDB As DAO.Database
-
Dim ResidentMedications As DAO.Recordset
-
Dim ResidentMedicationDetailTable As DAO.Recordset
-
Dim intDayCtr As Integer
-
Dim doses As Integer
-
Set MyDB = CurrentDb
-
Set ResidentMedications = MyDB.OpenRecordset("ResidentMedications", dbOpenForwardOnly)
-
Set ResidentMedicationDetailTable = MyDB.OpenRecordset("ResidentMedicationDetailTable", dbOpenDynaset)
-
-
-
-
'Loop thru all the Records
-
With ResidentMedications
-
Do While Not .EOF
-
'Break down the Date Range into Linear Dates and ADD to ResidentMedicationDetailTable
-
For intDayCtr = 0 To DateDiff("h", ![FirstDose], ![LastDose])
-
ResidentMedicationDetailTable.AddNew
-
ResidentMedicationDetailTable![DoseDate] = DateAdd("d", intDayCtr, ![Scheduledstartdate])
-
ResidentMedicationDetailTable![dosetime] = DateAdd("h", intDayCtr, ![FirstDose])
-
ResidentMedicationDetailTable![Medication] = ![Medication]
-
ResidentMedicationDetailTable![MedicationID] = ![MedicationID]
-
ResidentMedicationDetailTable![ResidentID] = ![ResidentID]
-
ResidentMedicationDetailTable![dosetime] = ![FirstDose]
-
-
'ResidentMedicationDetailTable![dosetime] = ![Dose2]
-
ResidentMedicationDetailTable![dosetime] = DateAdd("h", intDayCtr, ![FirstDose])
-
ResidentMedicationDetailTable.Update
-
Next
-
.MoveNext
-
Loop
-
End With
-
-
ResidentMedicationDetailTable.Close
-
ResidentMedications.Close
-
Set ResidentMedications = Nothing
-
Set ResidentMedicationDetailTable = Nothing
End Sub
Thank you in advance for any help you can give me!
Assuming you have a [DoseDate] Field in a Table named Table1. The following Code will display all Dates along with the 24 Hours of each Date starting at 8:00 A.M. - Dim MyDB As DAO.Database
-
Dim rstDates As DAO.Recordset
-
Const conBASE_TIME As Date = #8:00:00 AM#
-
Dim bytCtr As Byte
-
-
Set MyDB = CurrentDb
-
Set rstDates = MyDB.OpenRecordset("SELECT DISTINCT [DoseDate] from Table1 ORDER BY " & _
-
"[DoseDate];", dbOpenForwardOnly)
-
-
Debug.Print "----------------------"
-
-
With rstDates
-
Do While Not .EOF
-
For bytCtr = 0 To 23
-
Debug.Print ![DoseDate] & " | " & _
-
Format$(DateAdd("h", bytCtr, conBASE_TIME), "hh:mm AM/PM")
-
Next
-
Debug.Print "----------------------"
-
.MoveNext
-
Loop
-
End With
-
-
Debug.Print "----------------------"
-
-
rstDates.Close
-
Set rstDates = Nothing
RESULTS: - ----------------------
-
9/19/2013 | 08:00 AM
-
9/19/2013 | 09:00 AM
-
9/19/2013 | 10:00 AM
-
9/19/2013 | 11:00 AM
-
9/19/2013 | 12:00 PM
-
9/19/2013 | 01:00 PM
-
9/19/2013 | 02:00 PM
-
9/19/2013 | 03:00 PM
-
9/19/2013 | 04:00 PM
-
9/19/2013 | 05:00 PM
-
9/19/2013 | 06:00 PM
-
9/19/2013 | 07:00 PM
-
9/19/2013 | 08:00 PM
-
9/19/2013 | 09:00 PM
-
9/19/2013 | 10:00 PM
-
9/19/2013 | 11:00 PM
-
9/19/2013 | 12:00 AM
-
9/19/2013 | 01:00 AM
-
9/19/2013 | 02:00 AM
-
9/19/2013 | 03:00 AM
-
9/19/2013 | 04:00 AM
-
9/19/2013 | 05:00 AM
-
9/19/2013 | 06:00 AM
-
9/19/2013 | 07:00 AM
-
----------------------
-
9/20/2013 | 08:00 AM
-
9/20/2013 | 09:00 AM
-
9/20/2013 | 10:00 AM
-
9/20/2013 | 11:00 AM
-
9/20/2013 | 12:00 PM
-
9/20/2013 | 01:00 PM
-
9/20/2013 | 02:00 PM
-
9/20/2013 | 03:00 PM
-
9/20/2013 | 04:00 PM
-
9/20/2013 | 05:00 PM
-
9/20/2013 | 06:00 PM
-
9/20/2013 | 07:00 PM
-
9/20/2013 | 08:00 PM
-
9/20/2013 | 09:00 PM
-
9/20/2013 | 10:00 PM
-
9/20/2013 | 11:00 PM
-
9/20/2013 | 12:00 AM
-
9/20/2013 | 01:00 AM
-
9/20/2013 | 02:00 AM
-
9/20/2013 | 03:00 AM
-
9/20/2013 | 04:00 AM
-
9/20/2013 | 05:00 AM
-
9/20/2013 | 06:00 AM
-
9/20/2013 | 07:00 AM
-
----------------------
12 1202
I'm sorry. How do I do that?
zmbd 5,501
Expert Mod 4TB
topdesk123
How to add the code tags: > Before Posting (VBA or SQL) Code
If you'll take a few moments to do the setup for options etc... as given in the first section and the links within this article, it will save us some time too (-_-)
zmbd 5,501
Expert Mod 4TB
topdesk123:
The second block of code, is this the actual code that you are using for your project, or is this the code you borrowed as an example?
If this is not the actual code then please post that instead.
Also, which old thread of ADezii were you reading? It might help to have that context.
If I interpret your request correctly, you can use Nested Loops to solve the problem. The Outer Loop would consist of Unique Dates Ascending. The Inner Loop would consist of each Hour for the given Unique Date (24 hrs.) Ascending. The Value of Date and Time for each Iteration of the Loop would be appended to a New Table.
Zmbd,
The Code I posted is the actual code I'm using.
Hi ADezii,
I have been searching and reading other forums on nested loops - but I just don't get it. Can you give me a hint?
Assuming you have a [DoseDate] Field in a Table named Table1. The following Code will display all Dates along with the 24 Hours of each Date starting at 8:00 A.M. - Dim MyDB As DAO.Database
-
Dim rstDates As DAO.Recordset
-
Const conBASE_TIME As Date = #8:00:00 AM#
-
Dim bytCtr As Byte
-
-
Set MyDB = CurrentDb
-
Set rstDates = MyDB.OpenRecordset("SELECT DISTINCT [DoseDate] from Table1 ORDER BY " & _
-
"[DoseDate];", dbOpenForwardOnly)
-
-
Debug.Print "----------------------"
-
-
With rstDates
-
Do While Not .EOF
-
For bytCtr = 0 To 23
-
Debug.Print ![DoseDate] & " | " & _
-
Format$(DateAdd("h", bytCtr, conBASE_TIME), "hh:mm AM/PM")
-
Next
-
Debug.Print "----------------------"
-
.MoveNext
-
Loop
-
End With
-
-
Debug.Print "----------------------"
-
-
rstDates.Close
-
Set rstDates = Nothing
RESULTS: - ----------------------
-
9/19/2013 | 08:00 AM
-
9/19/2013 | 09:00 AM
-
9/19/2013 | 10:00 AM
-
9/19/2013 | 11:00 AM
-
9/19/2013 | 12:00 PM
-
9/19/2013 | 01:00 PM
-
9/19/2013 | 02:00 PM
-
9/19/2013 | 03:00 PM
-
9/19/2013 | 04:00 PM
-
9/19/2013 | 05:00 PM
-
9/19/2013 | 06:00 PM
-
9/19/2013 | 07:00 PM
-
9/19/2013 | 08:00 PM
-
9/19/2013 | 09:00 PM
-
9/19/2013 | 10:00 PM
-
9/19/2013 | 11:00 PM
-
9/19/2013 | 12:00 AM
-
9/19/2013 | 01:00 AM
-
9/19/2013 | 02:00 AM
-
9/19/2013 | 03:00 AM
-
9/19/2013 | 04:00 AM
-
9/19/2013 | 05:00 AM
-
9/19/2013 | 06:00 AM
-
9/19/2013 | 07:00 AM
-
----------------------
-
9/20/2013 | 08:00 AM
-
9/20/2013 | 09:00 AM
-
9/20/2013 | 10:00 AM
-
9/20/2013 | 11:00 AM
-
9/20/2013 | 12:00 PM
-
9/20/2013 | 01:00 PM
-
9/20/2013 | 02:00 PM
-
9/20/2013 | 03:00 PM
-
9/20/2013 | 04:00 PM
-
9/20/2013 | 05:00 PM
-
9/20/2013 | 06:00 PM
-
9/20/2013 | 07:00 PM
-
9/20/2013 | 08:00 PM
-
9/20/2013 | 09:00 PM
-
9/20/2013 | 10:00 PM
-
9/20/2013 | 11:00 PM
-
9/20/2013 | 12:00 AM
-
9/20/2013 | 01:00 AM
-
9/20/2013 | 02:00 AM
-
9/20/2013 | 03:00 AM
-
9/20/2013 | 04:00 AM
-
9/20/2013 | 05:00 AM
-
9/20/2013 | 06:00 AM
-
9/20/2013 | 07:00 AM
-
----------------------
Thank you! Thank you! Thank you! Thank you! ADezii YOU ROCK!
My tables are ResidentMedications and ResidentMedicationsDetailTable, the first table contains the data I am trying to move and expand into the second table based on the fields ScheduledStartDate and ScheduledEndDate and FistDose(Time) and LastDose (time). I am going to try and get your suggestion to work with this. Again, thank you!
You are quite welcome, topdesk123.
A step further...I got this code to work nearly perfectly. - Dim MyDB As DAO.Database
-
Dim ResidentMedications As DAO.Recordset
-
Dim ResidentMedicationDetailTable As DAO.Recordset
-
Dim intDayCtr As Integer
-
-
Set MyDB = CurrentDb
-
Set ResidentMedications = MyDB.OpenRecordset("ResidentMedications", dbOpenForwardOnly)
-
Set ResidentMedicationDetailTable = MyDB.OpenRecordset("ResidentMedicationDetailTable", dbOpenDynaset)
-
-
'Clear all Records in ResidentMedicationDetailTable
-
'CurrentDb.Execute "DELETE * FROM ResidentMedicationDetailTable;", dbFailOnError
-
-
-
With ResidentMedications
-
-
Do While Not .EOF
-
-
'Break down the Date Range into Linear Dates and ADD to ResidentMedicationDetailTable
-
For intDayCtr = 0 To DateDiff("d", ![Scheduledstartdate], ![Scheduledenddate]) - 1
-
ResidentMedicationDetailTable.AddNew
-
ResidentMedicationDetailTable![Dosedate] = DateAdd("d", intDayCtr, ![Scheduledstartdate])
-
ResidentMedicationDetailTable![Dosetime] = (DateAdd("h", bytCtr, [FirstDose] + [Interval] / 24))
-
ResidentMedicationDetailTable![ResidentID] = ![ResidentID]
-
ResidentMedicationDetailTable![Medication] = ![Medication]
-
ResidentMedicationDetailTable![MedicationID] = ![MedicationID]
-
ResidentMedicationDetailTable.Update
-
Next
-
.MoveNext
-
Loop
-
End With
-
-
-
-
-
'rstDates.Close
-
' Set rstDates = Nothing
-
-
End Sub
However I am wondering how to write the do while statement to say something like "Do while [Dosedate] is between [scheduledstartdate] and [scheduledenddate] and [dosetime] is before [lastdose]. I've tried several variations and continue getting syntax error messages.
thanks in advance.
zmbd 5,501
Expert Mod 4TB
However I am wondering how to write the do while statement to say something like "Do while [Dosedate] is between [scheduledstartdate] and [scheduledenddate] and [dosetime] is before [lastdose]. I've tried several variations and continue getting syntax error messages.
Open the VBA-Editor, select the DO, press [F1] this will open the help file to the Do..loop statement help file. You will find your answer there. (^-^) Do...Loop Statement
YOu should also add the following links to your bookmarks: >Home Page for MS Access 2010 Developer's Reference Microsoft Access / VBA Insights Sitemap A wealth of information, tricks, and advice
Last but not least:
-> Respectfully, we ask for there to be only one question per thread. This helps to keep the topic on track and makes it easier for our memebers to find an answer for a given topic.
@topdesk123:
Create a New Thread as zmbd suggests, and I'm sure that one of us can point you in the right direction.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: StinkFinger |
last post by:
All,
Struggling with a query here.
table name : holidays
fields : holname (format varchar)
holdate (format date 2004-01-01)
The table is populated with all the holidays for the next 5 years....
|
by: Rick |
last post by:
I need to store a date prior to the unix epoch, any pointers?
--
Rick
Digital Printing
www.intelligence-direct.com
|
by: Steve |
last post by:
I am currently trying to validate data in an access database. I need
to verify that columns containing date information are in the format
ddmmyyyy and columns containg time information are in the...
|
by: Geoff Jones |
last post by:
Hi
I have a table that has a column with Date types.
I am trying to view certain rows in the table using a DataView.
Using the filter, I can view the rows with, for example, the date equal...
|
by: Danny |
last post by:
Hello there.
I'm creating a little text changer in Python. In the program there is a
while loop. The problem is that a while loop will have 1 print statement
and it will loop until it gets to...
|
by: dhoward |
last post by:
I'm having a certain situation. On my application, if a user has the choice to apply for the same permit more than once but on different times. Now the first application would be 100.00 but any...
|
by: gviteri |
last post by:
I apologize for not researching this information on my own but I am at work and need a quick fix.
I am running WRQ Reflections built on Visual Basic. I need to create a macro that first inquires...
|
by: =?Utf-8?B?cmF1bGF2aQ==?= |
last post by:
Hi:
(I know there are lots of different ways to do it) no regex, please
if we have string date yyMMdd "080230" whats the best way to test for valid
date ?
Feb will never have 30 days,
2)
if...
|
by: vikas251074 |
last post by:
Loop runs indefinite times.
suppose v_router = 5 is entered by user, then following code runs indefinite times i.e. record is inserted indefinite times though each have different i and v_ip_address....
|
by: jacc14 |
last post by:
I am creating a time sheet and want to compare 2 dates and times to find the length of time taken.
1. I have a start date in one field and start time in another. I then want to enter a finish...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |