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

"DO FORM" From within Valid Event?

Status
Not open for further replies.

Shanachie

Programmer
Jun 18, 2000
92
US
I am having a strange problem with my app. A form has a grid used to enter lines for a purchase order. One of the columns of the grid contains the item number, another contains the color number, and another the size number. When the user enters the color number or the size number, the valid event for that text box checks the number for validity for that item number. If the number isn't valid, a message to that effect is displayed via a form. The problem is that after DO'ing the form, the focus seems to be lost. You can enter other columns only by clicking on them and the tab and arrow keys no longer seem to do anything. Closing the form and reopening restores normal operation.

I tried setting focus after the DO FORM but you can't SET FOCUS in a valid event.

How do I get focus back and functioning tab and arrrow keys?

TIA,
Shanachie
 
Hi Shanachie,

After returning from your error message form you're probably re-firing some ACTIVATE code in the calling form. Check to see if this code is the culprit.

Jim
 
Unfortunately you cannot set focus in a VALID, and I believe that is true in a WHEN also.

I have 2 suggestions.

1. If your set on another form, instead of a messagebox, make the VALID call a method on the form.

Example of Valid

THISFORM.mycheck

Example of method mycheck

IF whatever I want
COOL
ELSE
MESSAGE
THEN SEE WHERE FOCUS IS AT
If necessary
THISFORM.grid.field.setfocus
ENDif
ENDIF


Option 2 is more basic. Just use a messagebox. I hope this make sense.


Jim Osieczonek
Delta Business Group, LLC
 
This is interesting. I tried substituting MessageBox() for my DO FORM and the problem went away, everything behaved properly. MessageBox(), however, does not look right. The format of the dialog just doesn't fit with the rest of the application. Besides, it seems to me that I should be able to call a form from within a Valid method, shouldn't I? So what am I missing to make this work properly?

Any suggestions?

Shanachie
 
You can certainly call a form from the Valid, but the new form then becomes the active one. When it's released your original form ACTIVATEs again, sometimes with surprising results. MESSAGEBOX() leaves the original form active.

Jim
 
It's not that you cannot call a form from a valid event, you can, but what pimps you is that the current focus changes because you are now on a new form, it's objects, etc., and since you cannot set focus in a valid you cannot set it back after control is passed back.

The messagebox does not change focus, and that is why it works properly. However, if it doesn't look the way you want, you have a couple of options.

1. Put the code in a form method and let the form method reset the focus.

i.e. THISFORM.myMessage.

* My message Method
DO FORM myMessage
* the form will be modal and after it is released.

THISFORM.txtMyfield.SETFOCUS

I think this will work.

If not, review the FAQ's. I think Mike has about an alternative messagebox than the normal messagebox. It may look more appealing.


Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top