2 questions about Forms

kirkm

Registered User.
Local time
Tomorrow, 10:13
Joined
Oct 30, 2008
Messages
1,257
Hi,

I've a Form with a text box, and an OK & Cancel button. Hitting Enter in the text box, shifts focus to the OK button and you have to hit it again.

Can Enter be made to close the form immediately?

Also, what is the method for setting the x,y position of the Form when it opens ?

Thanks - Kirk
 
Check for evenst such as LostFocus and GotFocus.

You use movesize.

The easiest is to use the movesize macro action and if prefer VBA then convert the macro. The reason is that in the macro the movesize dimensions are real numbers as in cms or inches and the other is "fips or pips" I can nver remember the name but there are 1440 (I think) of them in an inch

Here is a copy of one I use

DoCmd.MoveSize , 567, , 12209

That is setting the distance from the top of the screen to 1cm and the height of the form to 21.5cm. The main reason for the height is due to continuous forms.

You can set Right, Down, Width and Height

In a macro you simply enter the number you want.

Pop up forms need different numbers to get the same result.
 
Ok so you want when someone hits enter when they are in the text box that the form closes? First are you sure that the user will never want to cancel when they are in the text box and click enter? If that is what you want then in the properties of the text box go to the events and in the On Enter event put in DoCmd.close. To position the form where you want, you can use the On Forms Load or Open event use
DoCmd.MoveSize 2000, 2000, 2000, 2000

where 2000 is distance from right, 2000 is distance from Top 2000 is width of form and 2000 is height of form. These measurements are in twips and there are approximately 1440 twips in an inch.
 
Ok so you want when someone hits enter when they are in the text box that the form closes? First are you sure that the user will never want to cancel when they are in the text box and click enter? If that is what you want then in the properties of the text box go to the events and in the On Enter event put in DoCmd.close.
Sorry poporacer, but the On Enter event does NOT mean when you hit the Enter key, it means when you enter the control (similar but slightly different from the Got Focus event).
 
Thanks everybody.... making great progress. I presume the values for MoveSize would have to be calculated, and include screen resolution. (If this was used on another computer?)
Similarly, found 'On Enter' wasn't it... pity ! Still experimenting with that.

Thanks - Kirk
 
Thanks everybody.... making great progress. I presume the values for MoveSize would have to be calculated, and include screen resolution. (If this was used on another computer?)
Similarly, found 'On Enter' wasn't it... pity ! Still experimenting with that.

Thanks - Kirk

Kirk:

For your ENTER key issue, you can use the KeyPress Event of the text box if you wish. I don't remember the key code for the enter key but you can check on the key press event for that code and if it happens then you can just run the click event of the button.
 
I have a solution, if anyone's interested. Found via Google -

Set the form's KeyPreview property to True, and you can then use the form's
KeyPress event.

Private Sub Form_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
MsgBox "You hit Enter"
End If

End Sub


This is acknowledged to Doug Steele, Microsoft Access MVP
http://www.pcreview.co.uk/forums/thread-3638049.php
 
set the command button property 'Default' to Yes. that will fire when you hit enter as long as no other command button has the focus.
 
set the command button property 'Default' to Yes. that will fire when you hit enter as long as no other command button has the focus.

my goodness...I can't believe I forgot that one. Good one Wazz!
 

Users who are viewing this thread

Back
Top Bottom