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

Form within a form 4

Status
Not open for further replies.

Phil Thoms

Programmer
Oct 31, 2005
245
GB
In VFP 6 is it possible to run or create a form within another form similar to defining a window within another window ?
Thanks
 
Yes, you can do it, but it's a bit messy. See my article Create a scrolling region within a form which explains one way of doing it - and also the limitations.

If that article doesn't address your particular problem, perhaps you can clarify what you are trying to achieve.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I am trying to use a window/form for searching a database which is visible in the main form. The user will type in the ID and then the window/form can be released after the ID is located.
 
Thanks Mike, but where would the user place search criteria after say he has hit a button labelled Find or Search ?
Thanks
 
The Window within a Window was typically used in OLD Foxpro to create separate and discrete regions within an overall FP Screen to use in a variety of ways.

With VFP Forms, that is no longer necessary. The individual regions can now be created with either PageFrames (i.e. 'tabbed' pages), separate sub-Forms, or merely putting a combinations of Textboxes and Grids onto the Form itself.

Typically Search criteria are put into one or more Textboxes on a Form and the values are then 'harvested' and used when a designated Button is clicked - whereby the Click Method code is executed.

The results of that Search, if the result is multiple records, can either be displayed in a different and separate sub-Form or in a Grid within the Form itself, or, if the results are just a single record, into other Textboxes on the same Form.

Good Luck,
JRB-Bldr
 
where would the user place search criteria after say he has hit a button labelled Find or Search ?

Sorry, Philthoms, but your thinking is a bit muddled. The user can't enter the search criteria after he hits the Search button. It has to be the other way round.

What you need is a form with the following controls:

1. A textbox for entering the search term.

2. A Find button.

3. A grid for displaying the results (assuming a given search can return multiple hits).

The user enters the search term, then clicks Find. In the Click event of the Find button, you write code that performs the search.

The search results are then displayed in the grid.

Optionally, you can add another button which opens a subsidiary form. This form shows the details of the record currently selected in the grid. If necessary, you can let the user edit the data in this form.

If the search always returns a single hit, you would do without the grid. Instead, either display the details in textboxes and similar controls - in the same form as the search; or directly open a subsidiary form (since there is only one hit, you don't need the user to select a row in a grid).

Does this makes sense?

Whatever else you do, forget about the "form within a form". It's not a good way to solve this particular problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks, becoming more clear now. As you can probably tell I am just migrating to VFP from FP 2.6. JRB-BLDR mentions a sub-form, can you explain a little more about sub-forms.
Many thanks.
 
My use of the term 'sub-form' refers to a Form which is called by another Form.

Typically it is done with something like:
Code:
* --- Somewhere within one of the Primary Form methods ---
* --- Perhaps in the Search Button Click Method ---

* --- Temporarily Hide This Form ---
ThisForm.Hide

* --- Run/Display Secondary Form ---
DO "OtherForm.scx"

* --- When Done with secondary form, have this one re-appear ---
ThisForm.Show

NOTE - Hiding the primary form is not necessary, but sometimes it is handy to keep the user from being 'confused' by 2 forms showing up.

Good Luck,
JRB-Bldr
 
main form with

grid (all records)
text (search text)
filter (search button)


the grid is use to entering the data and
if the user do the filter, then the grid
only display the filtered records

this scheme work well for me.

to emphasize in filter mode could change the backgroud or frame the grid with subtle color.

I prefer using one form, one grid!
 
If you are happy to have the user directly edit the data in the grid, then you don't need a subsidiary form.

In general, a grid is not the best tool for data entry or editing. Users usually prefer text boxes and similar controls. But it's up to you.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
How about creating another form, a modal form with the textbox for the search at the top, and a grid on the bottom to display records found.
In the valid event of the textbox do your search and display the results in the grid. Set the highlight control on the grid to more obviously set the selected record. Use the doubleclick of the grid to close the form and return the results to the calling form.
 
JerryFoote,

Welcome to the forum.

What you are suggesting is almost the same as my own suggestion, except that you are proposing to trigger the search from the Valid event rather than by clicking a button.

The only small problem with that is that it doesn't give the user an easy way to change their mind. If they enter a search term, then decide to cancel the form, the search will still run. In order to avoid that, they would have to delete the search term (and your Valid code would need to explicitly ignore an empty search term).

It's not a big problem, but it's one reason I try to avoid using the Valid event for anything except validation (and I rarely use it for that).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top