# Thread: Broken layout filter or broken programmer?

1. ## Broken layout filter or broken programmer?

In the course of making numerous small tweaks to my application, I seem to have somehow broken the ability to do filtering in reports. My application is such that I have an AfterUpdateRecords event to generate a report to a file, send it in an e-mail, then delete the file via the following code:

Code:
function AfterUpdateRecords as v (Args as P, PageVariables as P)
with PageVariables

format = "PDF"
filter = "ID = " + Args.DataSubmitted.R1.ID
order = ""
report.saveas(name,format,filter,order,filename,.F.)

body = "Please see attached file."

end with
end function
I could swear that the above code functioned perfectly last week (and even confirmed this by referencing an older backup), but now every time I trigger it, I get e-mailed a report that says "Report does not contain any records". If I change the filter to explicitly pick an existing record by ID (i.e.: filter = "ID = 1"), I get the same results. Only when I change the filter to be filter = "" do I get anything different (I get all the records). Being a numeric field, I also tried converting ID and Args.DataSubmitted.R1.ID using various functions, prior to concatenating it into a final filter expression.

Thinking it may be some WAS issue, I tried the same by opening the report in Design Mode, going to the Report menu and selecting Select Records. Attempting to use the same filters (even ID = n, where n=some record's ID) would result in a message when I generate the report stating "There are no pages in the layout". I even tried building it using the Expression Builder with no positive results.

Am I missing something embarassingly obvious?

Regards,
Tarek

2. Tarek,

You are right, the "Args.DataSubmitted.R1.ID" is type character, so it needs to be converted to numeric. You could do that either with the convert_type(ID,"N") or the val() methods.

Pat

3. Originally Posted by Pat Bremkamp
Tarek,

You are right, the "Args.DataSubmitted.R1.ID" is type character, so it needs to be converted to numeric. You could do that either with the convert_type(ID,"N") or the val() methods.

Pat
Pat, I did try this, but to no avail. Strangely enough, as soon as I changed it back to the original code above, it all started working again! I previously tinkered with this for hours with just about every variation I could think of and couldn't get it to work. If Args.DataSubmitted.R1.ID is truly a character type, then I don't know why it's working again now, given that my ID field is numeric.

Very strange..

Regards,
Tarek

4. If you to evaluate the filer expression

filter = "ID = " + Args.DataSubmitted.R1.ID

with a character value for Args.DataSubmitted.R1.ID, you would return a value of

"ID = 23"

or from the interactive window

?filter
= "ID = 23"

assuming the value "23" exists in Args.DataSubmitted.R1.ID. This result is a valid expression to filter on the numeric value in the id field. However, you may find that the dbf format sometimes has issues with evaluating numbers in filters. A more stable filter expression would be to convert the field value to character

filter = "alltrim(str(ID,12,0)) = \"" + Args.DataSubmitted.R1.ID+"\""

which would return

alltrim(str(ID)) = "23"

or

?filter
= alltrim(str(ID)) = "23"

from the interactive window.

5. Jerry, thanks for the tip. I've replaced my filter expression with yours and it's been working great.

Thanks again,
Tarek

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•