Problems passing a date from a form into Docmd.openreport - date

I am pulling my hair out because I just don't see what is wrong here. I suspect it is a simple/stupid error but just can't see it. I am a relatively inexperienced VBA programmer but I like to think literate enough to get by with most programing langages.
Problem
I have a simple Invoicing system. One of the reports I want to be produced is a report of all the invoices issues after a specific date.
To that end I have created a report "All invoice query" which uses a query of the same name to generate a summary of all the invoices in the system and deliver a one line summary (date, amount, paid flag)
I wanted to amend this so that I can limit the printout to invoices after a particular date.
I created a field (text box; format shortdate) in my dashboard to hold the date and a button to 'run' the report
The button calls the procedure
Private Sub ButtonAfterDate_Click()
DoCmd.OpenReport "All invoice query", acViewPreview, , "[Invoice date] > #" & Me.Printdate & "#"
End Sub
This produces a report with all of the invoices in the system (i.e. no filtering)
If I go to the table where the data in held [Invoices] and copy the date from there and paste it into the form control the report starts working and the report only displays the invoices after the date.
I have checked that my form control is set to shortdate, I have tried typing the date and selecting it with a date picker (no difference still fails to filter)
In desperation I have tried changing the control to a list box that uses a query to lift the dates from the Invoice table (however that failed so went back to my original control button and field to hold the date (with date picker)
In summary
If I copy and paste a date from the table into the form control the OpenReport behaves as expects and filters
If I type the date or use the date picker to put the date in the form control OpenReport ignores any filtering and displays all the invoice summaries.
It seems like a data type problem but am at a loss what to try next
Thanks in advance for any help

I have found the answer. I didn't realise that the where clause of the Docmd.OpenReport must have any dates in US format i.e. mm/dd/yyyy I am in the uk and the localisation on windows (and indeed uk practice) enters this as dd/mm/yyyy
After doing some research I found a function to re-write the date from uk to us format then put the amended string in the where clause.
I found the code to modify the date here :http://bytes.com/topic/access/answers/511395-dates-where-clause
but for convienience:
Public Function FixDate(strDate As String)
Dim D1 As Integer, D2 As Integer
D1 = InStr(strDate, "/")
D2 = InStr(D1 + 1, strDate, "/")
FixDate = CDate(Mid(strDate, D1 + 1, D2 - (D1 + 1)) & "/" _
& Left(strDate, D1 - 1) & "/" _
& Mid(strDate, D2 + 1))
End Function
posted by Randy Harris
tech at promail dot com
I then modify my event procedure to use this code:
Private Sub ButtonAfterDate_Click()
Dim mydate As Date
mydate = Me.Printdate
FixDate (mydate)
DoCmd.OpenReport "All invoice query", acViewPreview, , "[Invoice date] > #" & mydate & "#"
End Sub
And it works!
Thanks to all those who looked and had a think about it and I hope that it helps someone else.

Related

Google Sheets - DATE format not working on imported Date in TEXT format

I text based .csv file with a semicolon separated data set which contains date values that look like this
22.07.2020
22.07.2020
17.07.2020
09.07.2020
30.06.2020
When I go to Format>number> I see the Google sheets has automatic set.
In this state I cannot use and formulas with this data.
I go to Format>number> and set this to date but formulas still do not see the actual date value and continue to display an error
Can someone share how I can quickly activate the values of this array so formulas will work against them?
I would be super thankful
Where the date are in column A, starting in cell A1, this formula will convert to DATE as a number, after which you apply formatting to Short Date style.
=ARRAYFORMULA(IF(A1:A="",,DATE(RIGHT(A1:A,4),MID(A1:A,4,2),LEFT(A1:A,2))))
Hopefully(!) the dates stay as text, otherwise Google Sheets would sometimes detect MM/dd/yyyy instead of dd/MM/yyyy, and you won't be able to distinguish between July 9th and September 7th in your example.
Solution #1
If your locale is for instance FR, you can then apply
=arrayformula(if(A1:A="";;value(A1:A)))
solution#2
you can try/adapt
function importCsvFromIdv1() {
var id = 'the id of the csv file';
var csv = DriveApp.getFileById(id).getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csv);
csvData.forEach(function(row){
date = row[0]
row[0] = date.substring(6,10)+'-'+date.substring(3,5)+'-'+date.substring(0,2)
})
var f = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
f.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
First thanks to those that suggested a fix. I am not really a programmer and get cold sweats when I see suggesting of running scripts to solve simple problems. Sorry guys.
So the (non programmer) solution with the dates was to do a find/replace (CTRL + H) and replace all the (.)dots with (/)slashes, then to make sure the column is formatted as a date, then Google finally understands it as a date.
With the accounting values as well, I had to do the same find/replace to remove all the ' between thousands, then google woke up and understood them as numbers.
I am significantly underwhelmed by this from Google. They are getting too fat and lazy. They need some competition.

create a dynamic title that displays date range as per the start and enddate parameters used

I have a report that displays monthly and ytd amounts. I use start and enddate parameters that change according to the user. For example for startdate 4/1/2007 and enddate 2/28/2008
1. I need to display title as Monthly budget 2/1/2008 to 2/28/2008
2. I need to display title for YTD as YTD 4/1/2007 to 2/28/2008
I tried = Parameter!EndDate.value but it throws error
It looks like you may have missed a letter in your expression. It should be:
=Parameters!EndDate.Value
In the expression editor you can double click on the parameter name and it will insert it into the expression for you.
To get the full description that you mentioned, you'll need to use a combination of functions. One useful one to look at is DateAdd to add days and months to the specified date. Another one is FormatDateTime which allows you to use the standard "ShortDate" format.
If you run into further trouble, I would recommend posting a new question with the variations of code that you tried along with the specific error messages that you received.
You could try setting the Expression for a text box to:
="Monthly Budget " & FORMAT(Paramters!StartDate.Value, "MM/dd/yyyy") & " to " & "FORMAT(Paramters!EndDate.Value, "MM/dd/yyyy")
This will give you:
Monthly Budget 02/01/2008 to 02/28/2008
It is the same for your second requirement, just change the wording.

Set date in single line edit on opening

I'm using PowerBuilder 10.5 and I have two single line edit (SLE) fields - sle_date1 and sle_date2 on my window.
What I need is for those two fields to be filled once I open my program. sle_date2 has to have the value of today (for example - 09.07.13), and sle_date1 has to have the value of (sle_date2-30 days) (example 09.06.13).
So, as I said, once I open my programs both fields would be filled immediately with values of today's date and the date of a month before.
How could I do that? Any advice just to get me going?
You can add some code to populate the edits in the open() event of your window
with a given date that can be today(), you can compute a new date plus / minus a number of days with RelativeDate()
The following code just answers your question (though it could be better to use some editmask controls instead of singlelineedit as it would ease the handle of user's input):
date ld_now, ld_previousmonth
string ls_datefmt
ls_datefmt = "dd.mm.yy"
ld_now = today()
sle_1.text = string(ld_now, ls_datefmt)
ld_previousmonth= RelativeDate(ld_now, -30)
sle_2.text = string(ld_previousmonth, ls_datefmt)
It shows 09.07.13 and 09.06.13 at this time.
first of all you need to open your window. You can to this with put this code in your application open event (let suppose that your window is w_main):
open(w_main)
After that in put this code in your window's open event:
sle_date1.text = string(today())
sle_date2.text = string(RelativeDate(Today(), -30))
I think this solves your problem. Here is a little help for RelativeDate:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.pocketbuilder_2.0.pkpsref/html/pkpsref/pkpsref662.htm
Best Regards
Gábor

exhibit timeline date format

I have an exhibit timeline, my data is in format "2013-12-15T07:39:19.000-04:00" and I'd like to control how the date is displayed. Right now, it displays only day and month by default but I'd like it to display year as well.
My guess is exhibit using .js code?
If you want to format date to string the way you want,
Javascript can be tricky and you might have to parse on your own.
Something like this:
d = new Date("2013-12-15T07:39:19.000-04:00")
date_str = d.getDate() +"-" + d.getMonth() + "-" + d.getFullYear()
alert(date_str) //result depends on local computer timezone
Consider adding js library specific for date formatting, like momment.js (I have not tried it though)

How to change a cell's code after it's been moved in Excel using VBA

I have an Excel VBA Script I've written with help, I am not a neophyte when it comes to coding, but to me so far Excel VBA has been an arsenic nightmare wrapped in a sugar pill sold by MS as a language easy to learn.
Ok, rant out of the way sorry, but I digress.
Here is the complete script:
Option Explicit
Sub tgr()
Dim wsB As Worksheet 'BackOrder
Dim wsJ As Worksheet 'Jobs List
Dim wsA As Worksheet 'Archive
Dim LastRow As Long
Set wsB = Sheets("BackOrder")
Set wsJ = Sheets("Jobs List")
Set wsA = Sheets("Archive")
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
With Intersect(wsJ.UsedRange, wsJ.Columns("N"))
.AutoFilter 1, "<>Same"
With Intersect(.Offset(2).EntireRow, .Parent.Range("B:L"))
.Copy wsA.Cells(Rows.Count, "B").End(xlUp).Offset(1)
.EntireRow.Delete
End With
.AutoFilter
End With
LastRow = wsB.Range("B6").End(xlDown).Row
wsB.Range("P5:Q5").Copy wsB.Range("P6:Q" & LastRow)
Calculate
wsB.UsedRange.Copy Sheets.Add.Range("A1")
With Intersect(ActiveSheet.UsedRange, ActiveSheet.Columns("Q"))
.AutoFilter 1, "<>Different"
.EntireRow.Delete
With .Parent
.AutoFilterMode = False
Intersect(.UsedRange, .Columns("G")).Cut .Range("F1")
Intersect(.UsedRange, .Columns("H")).Cut .Range("G1")
Intersect(.UsedRange, .Columns("L")).Cut .Range("H1")
Intersect(.UsedRange, .Columns("N")).Cut .Range("I1")
Intersect(.UsedRange, .Range("B:J")).Copy wsJ.Cells(Rows.Count, "B").End(xlUp).Offset(1)
.Delete
End With
End With
LastRow = wsJ.Cells(Rows.Count, "B").End(xlUp).Row
wsJ.Range("M1:T1").Copy
wsJ.Range("B3:I" & LastRow).PasteSpecial xlPasteFormats
wsJ.Range("U1:W1").Copy wsJ.Range("J3:L" & LastRow)
wsJ.Range("X1:Y1").Copy wsJ.Range("M3:N" & LastRow)
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
As you can see this is a three page script, BackOrder, Jobs List, and Archive, what I need to do is in Archive. The cells in Columns in J & K use TODAY() as a way to tell the rest of the script when it looks in the cell in column F how many days early or late it is.
Column J shows early, Column K shows late.
Column J's script is:
=IF(F3-TODAY()<0,"",F3-TODAY())
Column K's script is:
=IF(TODAY()-F3<1,"",TODAY()-F3)
Column F in this case is part of the larger script, which moves data via an import and has no formatting.
Now, when I bring row into Archive, I want it to be where the cells, instead of having TODAY() in either script, I want it to show the date it was moved over there, so it will still be today, but instead of TODAY(), it will have the date in this format ##/##/##. It will "freeze" the count of J & K so it will be accurate from that day forward, so we will know if it was shipped late, early, or on time.
Is this possible, and if so how?
You are confusing worksheet functions and VBA functions. You stopped your rant too soon although I think Word VBA is the worst version.
With the user interface, I can go to cell A1 and type "4apr12". Excel recognises this as a date, stores the value as 41003 and sets the format to "dd-mmm-yy" which is the standard format closest to what I typed.
Alternately, I could type "41003" then go to the format menu and select or enter a date format of my choice.
Yet another choice is to type "=TODAY()". Excel stores the value as "=TODAY()" but because of the leading equals, it evaluates this as an expression when it is entered and displays the value as a standard date (format dd/mm/yy here in the UK) and re-evaluates the expression when the workbook is opened and saved and when told to do so via the Calculate options.
VBA functions are different. Even when they do the same thing, they often have different names. The nearest equivalent to TODAY() is Now(). This function returns the current date and time as a number. The integer part is the days since 1-Jan-1900; the fraction part is (Number of seconds since midnight)/(Number of seconds in a day). So at midday today, Now() would have returned "41003.5". This is a number; I can multiple it by two, subtract 5000 or whatever.
With VBA, I could execute:
Range("A1").Value = "4apr12"
Excel recognises this as a date just as if I had typed it from the user interface.
Alternatively, I could execute:
Range("A1").Value = 41003.5
This is just a number and will be stored and displayed as 41003.5.
If I want it to be displayed as a date, I must execute:
With Range("A1")
.Value = 41003.5
.NumberFormat = "dd mmm yy"
End With
The value is still saved as 41003.5 but I have told Excel to display it as 4 Apr 12.
I can execute:
Range("A1").Value = "=TODAY()"
This is treated just as if I had typed this formula from the interface.
But suppose I execute:
With Range("A1")
.Value = Now()
.NumberFormat = "dd mmm yy"
End With
Now() returns the current date and time as a number. Excel stores it as a number but displays it as a date because I have told it to. It will never re-evaluate because it is a simple numeric value not an expression involving functions.
I hope you this makes sense and helps you get your mind around the differences between Worksheet functions and VBA functions. Excel and VBA are like learning to drive a car. The first time you KNOW you will NEVER be able to do all these different things at the same time. Yet, a month or two later, you are playing with the pedals, the gear stick, wheel and indicator while checking the mirror. I do not understand why people think patting your head and rubbing your stomach is such as big deal. All I can say is that sudenly the mist will clear and Excel and VBA will make sense.