General Forms and Controls FAQ's

Why do I get an error when I use an expression as the ControlSource of a control?

The ControlSource property specifies the source of data to which an object is bound. Generally, the ControlSource property should contain the name of a field. If you need to display the result of a calculation through the evaluation of an expression, you can do so as follows:

∑       Leave the ControlSource property blank

∑       In the controlís Refresh method, enter: This.Value = <expression>

Why, when I run my form, is the List button on the toolbar always disabled?

It could be that the formís lAllowList property is set to .F. or you have not run the ProMatrix List Builder. See the Userís Guide for instructions on how to run the List Builder.

How do I simulate the clicking of a toolbar button through code?

All you have to do is run the Click method of the button. For example, the following simulates the clicking of the New button:

_SCREEN.oApp.oToolbar.cmdNew.Click()

Why, when running my form, do I continually get a "Do you want to save your changes first?" message when I havenít made any changes?

This can occur if you have code that either REPLACEs the value in a field or changes the contents of the Value property of a control that is bound to a field. VPM detects this change and prompts the user to save the change. To avoid this, your code should only set the value in a field if the value will actually be changed. Setting a field value to the same value is considered by VFP to be a change in value, resulting in the user being prompted to save the change.

Check for code that changes a field value in form and control methods, data dictionary code snippets, and Business Rules methods. You can also use the VFP function GETFLDSTATE(-1,<alias>) to identify the field that is being changed.

I have added code to the AddNew method in my form. Why do I get an "Operator/Operand type mismatch" error when I included DODEFAULT()?

If you place code into any method that has class code that must be run, you should make sure that you return to the calling procedure the value returned by the class code.

Instead of:

DODEFAULT()
<My Code>

Use the following:

lReturnValue = DODEFAULT()

<My Code>

RETURN lReturnValue

Why, when running my form, do I get an "Unknown member dataenvironment" error?

During the form creation process, if a form set was created when you changed the class of the form, you did not remove that form set. To fix this problem, open the form in the Form Designer. Then, select the Remove Form Set option on the Form menu.

Why canít I move the focus to a control by clicking on it?

If the focus moves to the control as expected when using the tab or arrow keys, the problem is probably that you have a shape control on top of the control that you are trying to click. If so, the shape control needs to be moved behind the other controls on the form. You can use the Send to Back option to do this.

If the focus does not move to the control as expected when using the tab or arrow keys, the problem is probably that there is code in the When event of the control that is preventing the control from receiving focus.

How do I close my form programmatically?

If the form is based on the Form_, Form_NoRecord, or Form_SingleRecord class, simply release the form with:

ThisForm.Release()

If the form is based on the Form_Toolbar class or a subclass, use the following code:

IF ThisForm.QueryUnload() AND _SCREEN.oApp.FormIsActive()

   ThisForm.Release()

ENDIF

Why canít I set a filter that references form or control properties?

Filter expressions cannot contain references to This or ThisForm because they have no meaning in a filter expression. You need to use either a global memory variable that is initialized in the application's main program or a public memory variable that is created in the form. For example:

RELEASE MyMemvar

PUBLIC MyMemvar

MyMemvar = This.Value

SET FILTER TO <field name> = MyMemvar

Why do I get a "Cannot find the builder program" error when trying to run a builder?

Most likely, the builder program that is registered with VFP is invalid or the path to it is incorrect. While in VFP, bring up the Options form from the Tools menu. Then, on the File Locations page, the Builders entry should specify the builder.app file that is in the VFP home directory. Make sure you click the Set as Default button.

Where would I put code that I want to be run each time a different record is displayed on my form?

Whenever a record is added or the record pointer is moved, the contents of the recordís fields are displayed on the form. At that point the formís EnableDisableToolbarControls method is automatically run. Therefore, code that needs to be run whenever a record is displayed should be placed in that method. For details on how to use the EnableDisableToolbarControls method, check out the comments in that method in the Form_Toolbar class in the VPMForms class library.

Why does pressing the Escape key cause changes on the form to be cancelled instead of just causing the form to close?

On forms based on the Form_Toolbar class and subclasses, pressing the Escape key causes the Click method of the toolbarís Cancel button to be run. This is consistent with other types of forms where you use the Cancel property of a button to cause the buttonís Click method to be run when the user presses the Escape key. The definition of the Cancel property of a commandbutton in the VFP help file reads: "Specifies whether a CommandButton or OLE Container control is the Cancel button; that is, if the user pressed the ESC key, the Cancel buttonís Click event would occur." The point being, that pressing the Escape key should cancel some process, not necessarily close the form.

You can make the pressing of the Escape key do what ever you like by changing the code in the Activate event of the Form_Toolbar class in the VPMForms class library. Just change the ON KEY LABEL ESC command.

What causes the "Table buffering is not enabled" error?

For a table edited through a grid, the tableís BufferModeOverride property in the DataEnvironment should be set to 5, optimistic table buffering.

If I open my formís cursors through code, how do I specify the InitialSelectedAlias cursor through code?

You can programmatically or manually set the formís cInitialSelectedAlias property. If programmatically, make sure you set the cInitialSelectedAlias property before the default Init event code is run, as follows:

ThisForm.cInitialSelectedAlias = "<alias>"

DODEFAULT()

As an alternative, you can programmatically set the InitialSelectedAlias property of the DE in the Init event as follows:

ThisForm.DataEnvironment.InitialSelectedAlias = "<alias>"

DODEFAULT()

Donít try putting this code in the Load method, because the Load method is run before the DataEnvironmentís Init event.

How do I avoid being asked if I want to save my changes?

There are two times when you are prompted to save your changes:

1.   When a change has been made and you click on a toolbar button that could potentially move the record pointer. You are prompted to save your changes prior to going on to another record because:

   It just makes sense for you to decide whether you want to save your changes while you still remember what changes you made to the record.

   With row buffering, as soon as the record pointer is moved, VFP automatically writes the contents of the buffer to the disk, which circumvents your ability to cancel your changes as well as the VPM Save routine where audit trail records are written, changes are cascaded, etc..

   You can bypass this prompt and automatically save your changes by setting the formís lAskToSaveMessage property to .F.

2.   Whenever you run a form based on the Form_Toolbar class or a subclass, make a change, do something to cause the form to be deactivated (like run another form), and then reactivate the form. The reactivation causes the formís Activate event to be run, where the toolbar (or on-form toolbar) is refreshed. When the toolbar is refreshed, the toolbar buttons are enabled and disabled depending on where the record pointer is positioned. In order to determine how the navigation buttons should be enabled and disabled, the record pointer must be moved so that it can be determined if the current record is the first record, last record, etc.. For the reason described in 1 above, this movement of the record pointer necessitates the prompt to save your changes.

   You can avoid this prompt in the following ways:

   By setting the formís lAutoSaveOnReactivation property to .T., your changes will be automatically saved upon reactivation.

   If the form uses a standard toolbar (not on-form toolbar), and is deactivated by a modal form being run that does not use a standard toolbar, you can set the form's lSkipActivate property to .T. prior to the modal form being run. This will prevent the formís Activate code from being run upon reactivation.

   If the form uses an on-form toolbar, and is deactivated by a modal form being run, you can set the form's lSkipActivate property to .T. prior to the modal form being run. This will prevent the formís Activate code from being run upon reactivation.

I get an error when I click the New button on my form. What could be causing this?

The first thing to check is any code you have entered as Default code, PreAdd code, or PostAdd code. Default code is entered through the Data Builder on the Code page after selecting a field. PreAdd and PostAdd code is entered through the Data Builder on the Code page after selecting a table, view, or cursoradapter. PreAdd and PostAdd code can also be entered into business rules methods in the ProDataHandlerBusinessRules class.

How do I make a form read-only?

To make the form read-only, set the formís lAllowEdits property to .F.

If you want the form to be read-only for certain users, you can either:

1.   Determine if the table should be read-only for the user, and if so, set the lAllowEdits property to .F.

2.   As a variation of (1) above, you could use two menu options to run the same form. One menu option, the read-only option, would pass a parameter to the form that would cause code in the form to set the lAllowEdits property to .F. You would then use Menu Security to control which of the two menu options each user could run.

How do I reference the properties and methods of the F2 Picklist (lookup) commandbutton?

The F2 Picklist (lookup) commandbutton name is derived from the name of the associated textbox. If the name of the textbox begins with "txt", the commandbuttonís name will be the same as the textbox, except the "txt" will be replaced by "cmdLookup". Otherwise, the commandbuttonís name will be the same as the textbox, except the name will be prefaced by "cmdLookup". For example, if the associated textbox is referenced with "ThisForm.txtEmployeeNo", the Click event of the F2 Picklist commandbutton would be run with:

ThisForm.cmdLookupEmployeeNo.Click()

How do I pass a parameter to a form?

Call the form as follows:

DO FORM <form name> WITH <parameter>

In the formís Init method, you need to include an LPARAMETERS command as follows:

LPARAMETERS <parameter>

DODEFAULT()

* Add code that uses the parameter.

More:

Related Forms and Related Pages FAQ's