DateDiff with french format - ms-access

I'm struggling with a problem about Dates manipulation.
Background :
Access 2013 - Classic Stock Table (id, name_item, record_date)
Currently working on SearchForm.
Have to finish the last filter (dates) - Others filters work.
I designed a ComboBox to filter "< 7 days", "< 30 days",...
PBM :
Date format is d/m/y (french format)
Operator < seems to compare with m/d/y even my date are defined in d/m/y.
I verified both Type in Table and Date(), they're set in d/m/y
CODE :
If InputDate.Value = "La semaine derniere" Then
strfilter = strfilter & "([Record_date] > #" & DateAdd("d", -7, Date) & "#)"
Debug.Print Month(DateAdd("d", -7, Date)) & " " & strfilter
Output :
9 ([Record_date] > #03/09/2015#)
I tried also strfilter = strfilter & "(Datediff('d', date(), [Record_date]) < 7)"
No difference :'(.
Any idea how I can go through this problem please.
Falt

You need the date value as a string expression formatted to yyyy/mm/dd:
strfilter = strfilter & "([Record_date] > #" & Format(DateAdd("d", -7, Date), "yyyy\/mm\/dd" & "#)"

Related

Dlookup value shows 0

while using Dlookup to find a "part No" while using a textbox and entering Part no that will match to the last date entry and bring all information .
Dim prtn As String
Dim temppart As String
Dim lastdate As Date
temppart = Me.Part_No.Value
lastdate = Nz(DMax("[Date Of Purchase]", "StockInventory", "[Part No]= '" & temppart & "'"), 0)
prtn = Nz(DLookup("[Part No]", "[StockList Query]", "[Part No]='" & temppart & "' AND [Date Of Purchase]= " & Format(lastdate, "\#mm\/dd\/yyyy\#")), 0)
here i can see lastdate carry last date, temppart carry the part no but value in prtn shows 0 ..
ComputerVersteher: missing of data column which was cause to get value '0' issue resolved after adding the column to the current query.

MSAccess VBA, filtering query results via combo box (text)

I want to filter date values (text) in a query based on a comboBox text value.
Here is what I have:
ComboBoxTimePeriod (ID [num], TimePeriod [text]).
In ComboBox I select Time period, like "16.10.2017-15.11.2017".
In a query I have Date field with single date, like "20.10.2017" (text).
What I want is to write an SQL code which searches for all records with date within TimePeriod range.
So far Idea is to extract SatrtDate and EndDate from TimePeriod like this:
Dim strStartDate As String
Dim strEndDate As String
strStartDate = Mid(Me.cboTimePeriod.Text, 1, 10)
strEndDate = Mid(Me.cboTimePeriod.Text, 12, 10)
Now from TimePeriod "16.10.2017-15.11.2017" I have StartDate (16.10.2017) and EndDate (15.11.2017).
And I want to filter all records which have date within those two dates.
This is where I need you guys.
Note that this is different issue from my last question, where I searched for a records with TimePeriodID (Subform filtering based off multiple parameters (Combobox AND Textbox)).
Always handle dates as Date, not text:
Dim StartDate As Date
Dim EndDate As Date
StartDate = DateValue(Split(Me.cboTimePeriod.Value, "-")(0))
EndDate = DateValue(Split(Me.cboTimePeriod.Value, "-")(1))
The build your filter:
... " Between #" & Format(StartDate, "yyyy\/mm\/dd") & "# And #" & Format(EbdDate, "yyyy\/mm\/dd") & "#"
To filter a form:
Me.Filter = "[Date Field] Between #" & Format(StartDate, "yyyy\/mm\/dd") & "# And #" & Format(EbdDate, "yyyy\/mm\/dd") & "#"
Me.FilterOn = True
And do make sure that your Date Field is of data type Date, not Text.

convert yyyymmdd to dd MMM yyyy

Is it possible to convert date 4 digit year 2 digit month and 2 digit day to dd (3 digit month) 4 digit year?
Right now I have the input of date "use date" as user entered YYYYMMDD. I prefer to use the calendar input as it keeps the date consistent
A Date/Time value is actually a double precision float number.
So you can take a number, and use CDate to represent it as a date.
? CDate(41668.0)
1/29/2014
The display format of the date value is a separate issue. The same numeric date value can be displayed in whatever format you prefer.
? Format(CDate(41668.0), "yyyymmdd")
20140129
? Format(CDate(41668.0), "dd mmm yyyy")
29 Jan 2014
But the actual date value (the number) is unchanged --- that number doesn't get "converted" regardless of how it's displayed.
If your issue is that the users are working with a text value instead of a Date/Time value, you either have to convert that text to a valid Date/Time value or modify your application so they enter Date/Time values instead of text.
The second alternative is less fuss. But if you're stuck with dates as text, you can do something like this ...
use_date = "20140129"
' transform it to a string CDate can accept ...
? Left(use_date, 4) & "-" & Mid(use_date, 5, 2) & "-" & Right(use_date, 2)
2014-01-29
' get the date from that string ...
? CDate(Left(use_date, 4) & "-" & Mid(use_date, 5, 2) & "-" & Right(use_date, 2))
1/29/2014
' finally make it a string in your desired format ...
? Format(CDate(Left(use_date, 4) & "-" & Mid(use_date, 5, 2) & "-" & Right(use_date, 2)), "dd mmm yyyy")
29 Jan 2014
try
DIM DateStr : DateStr = "20140119" 'Your date
Response.Write "DEBUG: DateStr = " & DateStr & "<br>"
'Split number so can use Date functions
DIM NewDate : NewDate = DateSerial(CInt(Mid(DateStr, 1, 4)), CInt(Mid(DateStr, 5, 2)), Mid(DateStr, 7, 2))
Response.Write "DEBUG: NewDate = " & NewDate & "<br>"
TheDate=CDate(NewDate)
Response.Write "DEBUG: CDate(NewDate) = " & TheDate & "<br>"
DIM FinalDate: FinalDate = DatePart("d", TheDate) & " "
FinalDate = FinalDate & MonthName(Month(TheDate),1) & " "
FinalDate = FinalDate & DatePart("yyyy", TheDate)
Response.write "DEBUG: Required Date = " & FinalDate

Scrollbar size wrong after filtering a forms record source

The forms recordsource is 1900 records & then gets filtered based on what user selects in a combobox list, in VBA I have a SELECT CASE statement to do something like the below for each selection
Private Sub cmbDateRange_AfterUpdate()
SELECT CASE Me.cmbDateRange.Value
Case "Yesterday"
Me.Filter = "messageDateandtime BETWEEN #" & Date - 1 & "# AND #" & Date - 1 & " 23:59#"
Case "Past 7 Days"
Me.Filter = "messageDateandtime BETWEEN #" & Date - 7 & "# AND #" & Date & " 23:59#"
End Select
Me.FilterOn = True
Me.Recordset.MoveLast: Me.Recordset.MoveFirst
The last line is a cheap hack that is working to fix the scroll bars being long for the original record set 1900, whereas this filter should be like 100. I am guessing there is a better/more-efficient way?

Form Filter using DateSerial does not work correctly

I'm trying to filter a form between dates - first and last of the next month. My coding for the last seems to work.I have also made a text box which does return the date I want but the same code in the filter is returning dates from 01 Jan 2013.
Public Function DtFrom() As Date
DtFrom = DateSerial(Year(Date), Month(Date) + 1, 1)
End Function
Me.Filter = "[DateDue] Between #" & DtFrom & "# And #" & (DateSerial(Year(Date), Month(Date) + 2, 1) - 1) & "#"
"[DateDue] Between #" & DtFrom() & "# And #" &
make sure you are calling the function DtFrom() 'yes you need the parenthesis