Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

Hello colleagues!

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

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,

RE: How to copy labels and fields from a form to a report

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.


RE: How to copy labels and fields from a form to a report

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.


RE: How to copy labels and fields from a form to a report

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


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()

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.


RE: How to copy labels and fields from a form to a report

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 Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to copy labels and fields from a form to a report

It is perhaps not what your goal was...


Peace worldwide - it starts here...

RE: How to copy labels and fields from a form to a report


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.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close