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!

Required field 1

Status
Not open for further replies.

rclarke

Technical User
May 14, 2001
78
0
0
GB
Hello

In Access there is a property you can set to say that that field is a required field so the user must enter data into that field. Is there a similar thing in fox pro.

RAchel ::)
 
Nope, mostly you handle this with record or field validations, that the programmer writes himself/herself.

Most frameworks use a so called business object, that sets the rules for data to be stored (obligatory fields, restrictions on values etc.).

The best way to validate if data has been entered is to notify the user that data has to be entered when the user leaves the control and/or notify the user when he/she tries to save the data (and can of course only save data when required data has been entered).

I have also seen Software packages that color their controls as beeing obligatory and use the forementioned validations.

HTH,
Weedz (Wietze Veld) They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best. - Steve McConnell
 
Thank Weedz

That is what I though so I wrote one

but as always when try to write code it does not work right

See Below

IF thisform.org_scontact1.value = Null
nAnswer=MessageBox('you have not filled in Account Code You must fill this in before you can continue', 16)
If nAnswer=1
RETURN
EndIF
EndIF

I put this in the save button so as they tried to leave the form it would not let them but it shows them the message regardless of if data is entered into the field or not.

 
HI,
In your save cmethod.. that is in the click event of your save button.. you have to put the code...

IF EMPTY(ThisForm.myTxtBox.Value)
=MESSAGEBOX("MyTextBox shall not be Blank.",0+16, ;
"Data Entry Error")
ThisForm.MyTextBox.SetFocus
RETURN .F.
ELSE
DODEFAULT()
ENDIF

** In the above method, irrespective of user passing thru the textbox (If the text box is passed thru only, valid event of that gets fired), the validity is checked. Also it is easy to handle all such form level controls in one place, as to thier validity.

Best of luck:)
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Ramani

What would I do without you

Thank you

If you ever have any trouble in opening pickle jars then do not hesitate to ask me
 
Just a bit of nitpicking (once more)...

Be aware that your user can also close the form by clicking the 'X' in the top right conrner of your form.

Let's say, you want to give your user the option to Save or Cancel, it is better to make a Save method on your form than in the click event of your save button (actually this is the first rule I learned doing a VFP course some years ago, never put too much code in the click event of a command button... ;-) ).

In this case you could do something like:

cmdSave.Click

THISFORM.SAVE()

And when your user clicks on the X

Form.QueryUnload

If MessageBox('Save Changes?', 48) == 6
THISFORM.Save()
RETURN DODEFAULT()
ELSE
NODEFAULT
ENDIF

The 48 should be Yes, No , Cancel (I could remember the exact number ;-) )


HTH,
Weedz (Wietze Veld) They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best. - Steve McConnell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top