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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to copy labels and fields from a form to a report 1

Status
Not open for further replies.

SitesMasstec

Technical User
Sep 26, 2010
470
1
18
BR
Hello colleagues!

I have created a form with lots of labels and their correspondent fields. Please see my form:

camposcadastro_jvpfzd.jpg


Now I need to create a report will all those labels and fields, in a similar layout. I tried copy and paste, but it doesn't work...

Will I have to put all fields manually in the report? If the answer is "yes", then I'll have to use the same amount of time to create the form.


Thank you,
SitesMasstec
 
Yes, the report controls "label" is not the same as the form controls label and the report controls field is not a textbox.

There is no correspondance, so there is no copy&paste.

Chriss
 
Dear SitesMasstec,

You can try using Report Wizard, if the report fields are based on a table or tables.

1. In VFP IDE, choose Tools -> Wizard -> Report.
2. It will give your option to select report from a Single table or Parent-Child tables. Choose as per your need.
3. Next screen, select your table under Database and Tables. It will show you the fields from the table you chose.
4. Select your fields using the single or double arrow keys.
5. Next screen will ask if you want Grouping. Choose accordingly.
6. Then choose your report style and then the layout in next screen.
7. Choose Sort accordingly.
8. Finally choose a folder and report file name.

The resultant file will have all fields you choose and labels for them.
(This will at least save your time typing in all the fields and labels for each field)

Then you can edit according your needs.

Note: If you just want to bring the fields, you can skip (ie to just click Next...Next...) all intermediate steps.

Rajesh
 
You can get at the clipboard data that's available if you copy a selection of form controls to the clipboard.
But I doubt you get happy with it, i.e. it takes a lot of work to transform the clipboard data you get from copying a selection of form controls vs the data you need to paste into a report.

If you copy form controls you get records that are in the same structure as records of an SCX or VCX form or form class.
If you copy from a report you get records that are in the same structure as records of an FRX report.

Try it yourself:

Step 1:
Execute this line by line in the command window
Code:
CD Home()
Set Library To Foxtools.fll
? OpenClip(0) && should be .T.

Step 2:
After doing this, open the form, select all form controls and copy them with CTRL+C. You can optionally cCeck, whether you have all controls by creating a new form and use CTRL+V to paste what you have in the clipboard.

Step 3:
execute this line by line in the command window
Code:
nFormat = EnumClipFm(0)
? nFormat && should be something in the range of 50000
? GetClipDat(nFormat) && should be a TMP file
USE (GetClipDat(nFormat)) Alias clipdata && only works, if GetClipDat(nFormat) is a TMP file, which is a DBF.
? CloseClip()
Browse

You should see data in the same structure as SCX/VCX. You can look into the Objname and Properties memos to find the object names (like label1, label2, etc.) and their properties (top,left,width,height, caption etc.)

Now you would need to translate this into the structure of FRX records of report labels and report fields. The task starts at finding out how to translate top,left,width,height into report control positions and sizes, which are stored in the records of an FRX.

The same code and steps 1-3 also work, if you open a report n step 2 and copy report controls into the clipboard. The clipdata workarea will then have the data structure of an FRX.

If you're willing to write a data transformation for that you could reuse it and program a tool that can transform clipboard data of a form to clipboard data of a report or vice versa and then perhaps even paste that, but I stopped here after finding out how to get at the clpboard data. It's less work to redo the form layout in a report for one form-to-report conversion. What Rajesh told you, will help you get all table fields into a report quickly, so you only have to arrange the labels and fields.

Chriss
 
If the field are contained in one or more tables which are in a database, you can set each field's Caption property (in the table designer, which you open from MODIFIY STRUCTURE).

You can then drag the field, either from the database designer (MODIFY DATABASE) or from the project manager, into both the form designer and the report designer. When you do that, the captions go with it. This won't completely answer your question, not least because you have already created the form. And you would still have to manually arrange the fields in the desired layout. But it's something to keep in mind the next time you have this requirement.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Screenshot_2023-03-26_211246_nozy7w.jpg


It is perhaps not what your goal was...

Regards
Klaus


Peace worldwide - it starts here...
 
Klaus,

the idea is not that bad, you could display records, make screenshots and print them, but it would not print fields on white, as you usually want, so the form has to be made white in all aspects, also border, borders of textboxes, etc. And then you may have cut off fields as a textbox does not stretch automatically while a report field does.

So I think all in all there are more detail problems to solve than really just investing the time it takes to reproduce the layout in a report.

And besides automatic stretching of fields also vertically, the report can easily print multiple records, which would be another challenge to reproduce with screenshots.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top