>I have created a form where some fields are dependent on user input. Based on the users input, I want to programmitacally disable some fields. I can move around them with setfocus() events, but that doesn't stop the user from clicking on the fields.
>
>Any Ideas.
>
>TIA.
>
>Rob
Hi, I do this as follow:
At Form Menu, Create 2 new Procedure at Form: say WhenAdd, AfterAdd
* ThisForm.WhenAdd
ThisForm.CmdTop.Enabled = .F.
....
ThisForm.CobKey1.Enabled = .F.
....
* ThisForm.AfterAdd
ThisForm.CmdTop.Enabled = .T.
....
ThisForm.CobKey1.Enabled = .T.
....
* ThisForm.CmdAdd.Click
#Define CAPADD [Add New]
#Define CAPCOM [Complete Add]
#Define CAPUPD [Update Now]
#Define CAPCAN [Cancel Add]
IF This.Caption = CAPADD
* Add record code here
This.Caption = CAPCOM
ThisForm.CmdUpdate.Caption = CAPCAN
ThisForm.WhenAddThisForm.TxtStartFocus.SetFocus && Sure it won't go wrong place!!
ELSE
* Complete Add Code here
This.Caption = CAPADD
ThisForm.CmdUpdate.Caption = CAPUPD
ThisForm.AfterAddENDIF
* ThisForm.CmdUpdate.Click
#Define CAPADD [Add New]
#Define CAPCOM [Complete Add]
#Define CAPUPD [Update Now]
#Define CAPCAN [Cancel Add]
IF This.Caption = CAPUPD
* Update record code here
* No Change in CAPTION!
ELSE
* Cancel Add Code here
This.Caption = CAPUPD
ThisForm.CmdAdd.Caption = CAPADD
ThisForm.AfterAddENDIF
So, when user click Add new, 2 button Caption trigger and either User complete or cancel,
Trigger back!!
It will more easy to handle and you can make those two buttons as Class.. ^_^;
Then, even you can add a short-cut at Form to further add record especially for Grid!
e.g. call the click twice if it's CAPTION is CapCOM
* ThisForm.KeyPress
Lparameters nKeyCode, nShiftCtrlAlt
#Define CAPCOM [Complete Add]
Do case
case nKeyCode = -8 && F9 is press
NoDefault
If ThisForm.CmdAdd.Caption = CAPCOM
* Complete Add, of cos you need to Auto-Feed the Common key at Add New Code
ThisForm.CmdAdd.Click
* Add New Again, Going to add next OrdItems etc.
ThisForm.CmdAdd.Click
Endif
ENDCASE
You can maintain the system very comprehensive if you divide them OOP and
Clear Case Division!
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.