Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report with OLE 2

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
508
Brasil
Hello colleagues!

In a table I have a field named EMAANEX1 C 50 (Character, NOT a General field)

Inside that field it has this content (just the name of a picture): JOHNDOE.JPG

The John Doe picture (JOHNDOE.JPG) is saved in the sub-folder named \ANEXOS in the current application folder. So I have:
CADASTRO4(current application folder)\ANEXOS\JOHNDOE.JPG

ReportOLE_jmg32k.jpg


I am trying to show the John Doe picture in a Report, but I only get Syntax error when running the report.


Thank you,
SitesMasstec
 
Well, sometimes it is not a picture, it is a PDF file, so I added to the Print when:

Code:
LEN(ALLTRIM(EMAANEX1))>0 AND RIGHT(UPPER(EMAANEX1),3)<>"PDF"

But when running the Report, I go an error when there is a PDF file:

ReportOLEpdf_dxqprc.jpg


JPG is Ok:
ReportOLEjpg_direw4.jpg



Thank you,
SitesMasstec
 
Hi SMT,

Why not simply click "Image File Name" under "Picture/OLE Bound ..."

Screenshot_2024-08-06_073225_qh3crv.png


hth

MarK
 
Instead of testing [tt]RIGHT(UPPER(EMAANEX1),3)[/tt], I suggest you test [tt]UPPER(JUSTEXT(EMAANEX1))[/tt]. That way, you would cater for files that have an extension that is other than three characters long - or no extension at all.

More to point, how does a PDF filename get into the table in the first place? If EMAANEX1 is meant to hold the name of an image file, you should do the check at the point at which the filename is inserted into the table.

MIke

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Can you give an overview over file extensions in the EMAANEX1 field (I assume it is a field of a table, not a variable)?

Code:
Select Distinct JUSTEXT(EMAANEX1) as Extension FROM yourtable
If there are further extensions of files, that are not images, you better redesign the data.


Also, just applying your hard won new knowledge about reports driven by cursors: If you only want to print images, then only allow image file names in the field of a report cursor to print, i.e. first of all create a report cursor again, and just populate it with the data you actually want to print. When there is a file of wrong type, replace that with the filename of an empty image (white, maybe even just a fully transparent 1 pixel PNG image), and then you have no data that isn't a picture.

Did you not realize the advantage of having a report cursor? You can manipulate it as needed for the report, without changing data in the tables, so you don't need the print when conditions as often as you use them.

To me it seems either you have more exceptions than PDF and fail on that or the print when condition is only evaluated after the expression for the Picture/Ole control was evaluated, causing the error earlier than it can be avoided by the print when expression suppressing the PDF files. I'd need to experiment to verify that, but you'll not need to know why, if you simply apply what you learned and make use of report data preparation in a cursor so that you reduce the exceptions that "print when" or "remove line if blank" would need to cover. You have much more control about what to print, if you make use of the cursor technique and that's really fresh knowledge you just learned - or should be - so make use of it.

Chriss
 
... and from

Cathy Pountney - Visual Foxpro Report Writer ... said:
Picture/ActiveX Bound controls

To add a picture to the report, select the Picture/ActiveX Bound Control button from the
Report Controls toolbar and click somewhere on the report. This inserts a small Picture object
at the position of the mouse. You can also use the same click, stretch, and release method used
with shapes to size the picture as you add it to the report. As soon as the Picture object is
added to the report, the Report Picture dialog shown in Figure 10 is displayed.
...
The first thing you need to describe to the Report Designer is where to get the picture.
This is done with the Picture from option group and either the File text box or the Field
text box.

Picture from File

The File option tells the VFP Report Writer that the picture is a physical file, such as
MyPicture.JPG. Depending on how your application is designed, you may need to qualify the
file name with a partial or full path. If the file resides in a directory that is within the current
VFP search path, you won’t need the path. However, if the file doesn’t reside within VFP’s
search path, you need to qualify the file name with enough path information for the Report
Writer to find the file.
You may also select the ellipse (…) button to the right of the File text box to invoke the
standard Open dialog. From this dialog, you can navigate to the directory that contains the
picture and select it. Upon returning from the Open dialog, the File text box contains the name
of the file you selected—with the full path name.
It’s important to realize that only the minimum relative path needed to find
the file is saved with the report. The full path is only displayed in the text box
for your benefit.
Besides entering a file name in the File text box, you may also enter an expression that
returns the file name of the picture to print. This is a very powerful feature! Consider the
following situation.
You have an inventory table with hundreds of items. You have pictures to associate with
each of the items in the table. Sometimes, the same picture is used for several items. For
example, you have a widget that comes in red, white, and blue. The item exists in the
inventory table three times because the part number varies depending on the color. But you
only have one picture that shows all three widgets. You could design the Inventory table with
a General field and use APPEND GENERAL to insert the picture into each and every
Inventory item, but this would result in a lot of wasted space when the same picture is used for
multiple items.
A better approach is to leave the pictures as stand-alone files. In your inventory table, add
a field called PictureFile as a character or memo field. What is stored in this field is the name
(and path if necessary) of the picture that relates to this item. The picture itself is not stored in
the Inventory table. When you add the Picture object to the report, enter Inventory.PictureFile
in the File text box. Once the file name is obtained from the expression, the Report Writer
continues in its normal fashion looking for the file and printing it on the report.
[highlight #8AE234]Note: A common mistake when implementing this scenario is to enter
Inventory.PictureFile in the Field text box instead of the File text box. But
you have to realize that the picture itself is not contained in a field. It’s
contained in a stand-alone file and you’re just using an expression, which
happens to use a field, to point to the file.[/highlight]
Another example of when to use an expression is when you have to conditionally print a
picture. For example, assume your application is a multi-company application that prints
invoices. The company logo that prints at the top of the invoice differs based on which
company the particular invoice is for. For this situation, you can use an IIF() function to
determine which file to print, as shown here:
IIF(Invoice.Company = 'A', 'LogoA.JPG', 'LogoB.JPG')
If there are too many possibilities that make an IIF() function too complex, use a UDF or
method call to return the appropriate file name as shown here:
oApp.CompanyLogo(Invoice.Company)
Either of these examples tells the VFP Report Writer to evaluate the expression and print
the picture whose file name is returned by the expression. So, like I said previously, being able
to enter an expression for the file name is a very powerful feature!
Sorry! The ability to enter an expression for the file name is a feature
that was added to Visual FoxPro. Older FoxPro 2.x applications can’t
use this trick.

Picture from Field

The Field option tells the VFP Report Writer that the picture is stored within a General field in
a VFP table. The Report Writer extracts the picture file from the indicated field and prints it on
the report. If you’ve never used general fields to store pictures, don’t worry. It’s really easy.
Use the following code to create a table and add a few records with pictures.
CREATE TABLE Test (pk I, MyPicture G)
INSERT INTO Test (pk) VALUE (1)
APPEND GENERAL MyPicture FROM c:\pictures\LogoA.JPG
INSERT INTO Test (pk) VALUE (2)
APPEND GENERAL MyPicture FROM c:\pictures\LogoB.JPG
The picture files you append into the general fields still have to be one of the supported
formats of BMP, JPG, or ICO. Or do they? Hmmm…
This is where the ActiveX... er... I mean the OLE Bound stuff comes into play. What
happens if you append a Microsoft Word document or Excel spreadsheet into the general
field? As long as you have the associated application installed, the document prints on the
VFP Report. Now that is really cool! Think of the possibilities. However, keep in mind it only
prints within the area defined for the Picture object. So a multi-page Word document won’t
print in its entirety without you pulling some major tricks to break the document down into
separate documents appended into separate records.

The Picture Frame

There are three options in the “If picture and frame are different sizes” option group (see
Figure 10). These options allow you to tell the VFP Report Writer what to do when the size of
the picture does not match the size of the Picture object (frame) you placed on the report.
• Clip picture: This option tells the VFP Report Writer to position the upper left
corner of the picture in the frame and to chop off any portion of the picture that
extends beyond the right and bottom edges of the frame.
• Scale picture, retain shape: This option tells the VFP Report Writer to expand or
shrink the picture so that it fills the frame. However, it will retain the proportional
height and width of the picture, and thus, the original dimensions of the frame may
be changed.
• Scale picture, fill the frame: This option tells the VFP Report Writer to expand or
shrink the picture so that it fills the frame both horizontally and vertically. Because
the ratio between the height and width of the picture is probably different from the
ratio between the height and width of the frame, the picture may become distorted.

Center Picture

OLE objects that come from general fields of a table can vary in shape and size. By default,
the object is anchored in the upper left corner of the frame. Check the Center Picture check
box to center the object within the frame you’ve designed. This option is only available for
Picture from Fields, not Files.

hth

MarK
 
Hello Chris, Mark, Mike!

Mark:
I cannot use "Image file name" because the field EMAANEX1 can be MYFORO.JPG or "MYDOC.PDF", so the Control source type must be set to "Expression or variable name" to store "ANEXOS\"+EMAANEX1.

I tried RIGHT(UPPER(EMAANEX1),3)<>"PDF" in Print when but it failed maybe because it assumes a picture before testing Print when.

I also have an application that uses General field for pictures to be stored in the record, as you mentioned from Cathy Pountney book. But the case above is that the record can also store a name of a JPG picture or a PDF document.

Chris:
EMAANEX1 is a field of a table which stores the name of a JPG or PDF file.

Chris said:
If there are further extensions of files, that are not images, you better redesign the data.
Yes! I went to bed yesterday with this thought, if not a solution were found: To reserve EMAANEX1, EMAANEX2 and EMAANEX3 exclusively to store JPG files and create a new field EMAANEX4 to store exclusively a PDF file.

Mike: EMAANEX1, EMAANEX2 and EMAANEX3 is a field of a record that can store a name with JPG or PDF extension:
SelecAnexos_dlrugf.jpg



Thank you,
SitesMasstec
 
SitesMasstec,

I have understood that EMAANEX1 stores filenames, that's what you said already. You're very sure your only file types in it are JPG or PDF. Have you done the query I provided (of course you have to add in the right tablename) and seen, whether you hgave further types? Because then, a third or fourth file type could cause the same error as PDFs did before you used the print when condition.

SitesMasstec said:
MAANEX1, EMAANEX2 and EMAANEX3 exclusively to store JPG files and create a new field EMAANEX4 to store exclusively a PDF file.
Why would you need 4 fields for 2 file types? Also, you still don't get the major idea from what we teached:

You don't need to modify your tables, you just need to populate a cursor that only exists for the report temporarily and you can then split up files into as may fields as you think you need, but one thing would be for sure, a field of that cursor for images you want to print in the report Picture/Ole Control should only have image file names in it. The Problem is solved that way.

A furhter idea, that you didn't seem to have picked up: In such a cursor field - for images only - the records that have no image file name could be set to an empty image, so every record of the cursor will have an image filename and you can print the Picture(Ole control without any exceptions.

Chriss
 
Oh, Chris, yes, good!

I will use cursor as you suggested and before printing the report, if a file is not an image, I will make show the PDF icon image, or no image.

Thank you,
SitesMasstec
 
Thanks, Chris, for your idea:

RelatAnexos_ftfwf7.jpg


A picture is displayed, but when a PDF document name is stored, an image of the PDF icon is displayed instead.



Thank you,
SitesMasstec
 
Hi SMT,

I had a look at your I-Site [link masstec.com.br]Link[/url].

Since your doing business with hints and advice from this forum without mentioning it, you may want to start paying us for the time we invested in your projects - see all your threads and our answers on this site.

I wish you good luck but I'll stop answering any further thread from you.

KR

MarK
 
Hello Mark!

I always said "my application", etc in my threads when I need advice, in all these years. Of course the applications I work on, is for business use, mine or for others, as I am a programmer. I think most of the people who seek advices here are working on professional applications.

The site you saw is a display of more than 30 years of work, it is not applications I developed in the last years.

Anyway, I am very grateful for you and all member here who have helped me a lot.

I have searched for how to make a donation to Tek-Tips, since last year, but I have not found how.

I would like to make a donation, if possible, independently if you or others stop giving me helpful advices.


Thank you,
SitesMasstec
 
It's not a problem SitesMasstec my best friend.
I would gladly get a donation [2thumbsup]
PL78 1140 2004 0000 3312 0193 8422
I don't accept amounts that are too small ..... [santa3]

Have a nice time, Piotr (joker) :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top