MS Access Running Count in time series by ID - ms-access

I am attempting to add a running count to a time series table by API number. The running count would be an indicator of what production month a given well is in.
Table: MonthlyProd
Fields: API, YEAR, MONTH, LIQUID
Desired Field: RunningCount
Desired Result
I cannot quite figure out a Dcount expression in MS Access.
Edit* Current progress is as follows. Using the following Access query
ProdMonth: DCount("API","Monthly Production","API=" & [API] & " AND (YEAR<" & [YEAR] & " OR (YEAR=" & [YEAR] & " AND MONTHNUMBER<=" & [MONTHNUMBER] & "))")
Yields the following results
Running Total Not quite there
I assume I am off in the logic statement somewhere?

Try something like this:
DCOUNT("API","MonthlyProd","API=" & API & " AND (YEAR<" & YEAR & " OR (YEAR=" & YEAR & " AND MONTH<" & MONTH & "))")
This assumes API, MONTH, YEAR are numerical.

I found a solution.
I needed to format the Month and Year into a date serial number in one field.
The correct DCount function was as follows:
ProdMonth: DCount("API","MonthlyFix","API=" & [API] & " AND DateSer<=" & [DateSer])

Related

Populate Time Range In MS-Access

I am making a scheduling tool, which runs off of five-minute increments tied to the IDs of timeslots on another table. These timeslots have a start time, and stop time which are separate fields in the same record, and can be entered using a form, and I would like to create a range of five-minute increments as records between these two times.
The ultimate goal is to use these timeslots to make an outlook-style gui to show when there are timeslots.
I have been struggling to find a quick way to fill them in Access, and my attempts at coding are so pathetic I'm too embarrassed to show them.
Any advice would be greatly appreciated,
Thank you!
Sounds like you want to create a batch of five-minute increment records associated with a particular date. More than one way to accomplish. Simplest may be to have a table of time records. Each record would have a time value: 10:00, 10:05, etc. Then on UNBOUND form user selects time range start and end from comboboxes and enters a date in a textbox. An SQL action statement in VBA could be:
CurrentDb.Execute "INSERT INTO tblSchedules(SchedDate, SchedTime) " & _
"SELECT #" & Me.tbxDate & "#, Mins FROM tblTimes " & _
"WHERE Mins BETWEEN '" & Me.cbxStart & "' AND '" & Me.cbxEnd & "'"
Without this table of time records, VBA would use a looping structure to save one record at a time to destination table.
Dim strT As String, db As DAO.Database
strT = Me.cbxStart
Set db = CurrentDb
Do While strT <= Me.cbxEnd
db.Execute "INSERT INTO tblSchedules(SchedDate, SchedTime) VALUES(#" & Me.tbxDate & "#, '" & strT & "')"
strT = Format(DateAdd("n", 5, CDate(strT)), "hh:nn")
Loop
In these examples, time value is text, not an actual date/time type. This means a structure of "hh:nn" in 24-hour time: "01:00" ... "24:00". If you prefer to save as number or as a date/time type, modify tables and code as appropriate. Keep in mind that midnight for date/time type is stored without a time component and Format() function displays as 12:00:00 AM or 00:00:00. Example: Format(#1/1/2022#, "mm/dd/yyyy hh:nn:ss AM/PM") displays as 01/01/2022 12:00:00 AM. Ranges crossing midnight causes complication.

Extended formatting of expressions within a query

I'm writing a query to output to a report which will be printed and used as an internal business form. I'm having issues trying to get the date placeholders to output for records where these values are null. It's probably just easier to show the code:
IStatement: "For a period from " & Nz(FormatDateTime([DateFrom],2),"________") & " to " & Nz(FormatDateTime([DateTo],2),"________") & "inclusive at the rate of " & Nz(FormatCurrency([InclusiveRate]),"$______") & " per " & [InclusiveTimeFrame]
I'm trying to get a blank line eight spaces wide to display in the query when there is not date in the record. What the heck am I doing wrong?
FormatDateTime
will return string and never null hence your Nz isn't working. However, you could try iif(not isnull([DateFrom]), FormatDateTime([DateFrom],2),"________")
or write your custom function for validating the date field.

how to get the data from the mysql database where date is between the value of 2 datetimepicker

im using vb.net 2008 and mysql in xampp. i have two datetimepicker from form7. when the "display report button" is click then the summary form will show.it contains the datagridview that contains the informations. im trying to get the data from the database where the date_drop is between the value of two datetimepicker. Hope you can help me. Thanks in Advance :)
--here's my code for that but it doesnt give any data :(
ct = "Select j_id as 'Job Code',
cus_name as 'Customer Name',
date_drop as 'Date Drop'
from jobs
where date_drop between '" & DateTimePicker2.Value & "'
and '" & DateTimePicker1.Value & "' "
You mention datepicker1 is the start time and datepicker2 the end time.
So, even if the values from your datepickers are formatted correctly for presentation to MySQL, your query ends up saying something like
BETWEEN '2014-09-28' AND '2014-09-26'
There are no dates in that range; you need to provide the start date first in the BETWEEN clause, like so
BETWEEN '2014-09-26' AND '2014-09-28'
See how the earlier date comes first?
In actual fact, you'd be wise to use this formulation instead
where date_drop >= '" & DateTimePicker1.Value & "'
and date_drop < '" & DateTimePicker2.Value & "' + INTERVAL 1 DAY "
That gets the two ends of the range in the right order. It also works in cases where date_drop might not be precisely at midnight on the end date.

I am not able to run date datatype as SQL query in MS Access 2007

I have imported an Excel file in MS Access 2007 having date formated as dd-mm-yyyy. When I run the following query
SELECT Hours
FROM work_DA WHERE Date BETWEEN 01-05-2013 AND 09-5-2013;
I get only blank table with Hours field.
Please tell me how to run this query in MS Access.
It would be better if you mentioned your table structure.
From what I can figure, you have to use "FORMAT" function when you query the date.
Try this ..
sqlcommand is
"SELECT Hours FROM work_DA WHERE Date >= #" & format(01-05-2013,'dd-mm-yyyy') & _
"# AND Date <= #" & format(09-5-2013,'dd-mm-yyyy') & "#"
change the dates with variables

SSRS - expression warning for date time format

I need to grab the Month and Year info from 2 date/time parameters of my report (Start date and End date) into a textbox.
I used the following expression -
=MonthName(Month(Parameters!StartDate.Value)) & Format(Year(Parameters!EndDate.Value)) & " to " & MonthName(Month(Parameters!EndDate.Value)) & Format(Year(Parameters!EndDate.Value))
to get it into something like e.g. March 2012 to August 2012.
It works, however I keep getting the following Warning:
[rsRuntimeErrorInExpression] The Value expression for the textrun ‘Textbox18.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from type 'Date' to type 'Integer' is not valid.
Any ideas?
Thanks!
Is that the exact expression you are using? It doesn't seem like it is because:
that expression works without warnings (on my system)
it doesn't give the output that you indicate it does
the expression is wrong (it lists the year of the EndDate twice rather than the StartDate's year with the StartDate's month)
So I would guess that one of the functions in the actual expression is MonthName(Parameters!StartDate.Value) rather than MonthName(Month(Parameters!StartDate.Value)) which would give the error indicated.
This also works:
=MonthName(Month(Parameters!StartDate.Value)) & " " & Year(Parameters!StartDate.Value).ToString() & " to " & MonthName(Month(Parameters!EndDate.Value)) & " " & Year(Parameters!EndDate.Value).ToString()
Either that or this isn't the expression in Textbox18