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!

How to stop a VFP form from auto advancing to a different field? 2

Status
Not open for further replies.

montypython1

Technical User
Jan 12, 2005
187
US
Greetings,

How to stop a VFP form from auto advancing to a different field? I currently have "SET CONFIRM ON" in the LOAD of the form, which stops the user from typing data from one field and auto-advancing into another field. Unfortunately, it does not stop the user from holding the backspace key down and accidentally deleting data in a previous field (or multiple previous fields).

I would like to stop this behavior for the entire form, not just for a specific field.

Any suggestions?

Thanks,
Dave
 
There is no simple setting for thatin my knowledge, but you can suppress backspace on the condition, the field value is already empty.

Set the forms keypreview property .T., then in the forms keypress event add the following code:
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

* See help on Inkey() for a table of keycodes
If (nKeyCode = 127) And InList(nShiftAltCtrl,0,1,2)
   * mainly check if the value of the active control 
   * is empty already, before that, check if there is an
   * active control which has a value property.
   If Vartype(Thisform.ActiveControl)="O" AND ;
      PemStatus(Thisform.ActiveControl,"Value",5) AND ;
      Empty(Thisform.ActiveControl.Value)
      
      * suppress the keypress
      NoDefault
      * 'bing'
      ? Chr(7)
   EndIf
Endif

There is one thing more easy to do, though: Set a controls Format to K, then tabbing to that control selects the content of it, so a single backspace can delete it. Users won't then hold down backspace. You can of course combine both that and the above general keypress event. I have tested this, but havent got this in production, there might be a side effect I don't think of right now or controls, for which this won't work this way. Maybe a combobox in combo style will be better tested for it's displayvalue than it's value, but you should be able to extend that on your own.

Bye, Olaf.
 
Hi Olaf,

Thank you for you prompt reply.

Your suggestion worked beautifully ... I would have never through of simply suppressing the backspace key if a field is blank ... a very elegant solution.

As always, thank you.

Dave Higgins
 
There is one design flaw in it, I see now:

If you position the text cursor somewhere in the middle of a textbox and hold down backspace, the value will not be empty, when another backspace will back into the previous control.

So you better not test, if the value is empty, but if selstart of the control is 0.

Bye, Olaf.
 
For the sake of completeness:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

If (nKeyCode = 127) And InList(nShiftAltCtrl,0,1,2)
   If Vartype(Thisform.ActiveControl)="O" AND ;
      PemStatus(Thisform.ActiveControl,"SelStart",5) AND ;
      Thisform.ActiveControl.SelStart  = 0 AND ;
      Thisform.ActiveControl.SelLength = 0
      
      NoDefault
      ? Chr(7)
   EndIf
Endif

This takes into account, that a part of the text in a control can be selected, beginning from the startposition 0. Then Keypress is not suppressed and thus allows to delete that selection while the next backspace then will find both selstart and sellength being 0.

To test, write something into a textbox, then select all via doubleclick and hit backspace.

Bye, Olaf.
 
Thanks Olaf,
I will implement your suggestion when I return to my office this evening.
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top