Command button on got focus not working

  • Thread starter gsnidow via AccessMonster.com
  • Start date
G

gsnidow via AccessMonster.com

Greetings all. I've got a popup form for adding a note to a notes table. On
the form there is a command button to insert the note then close the add note
form. It works fine when sub fires from the on click event of the button.
However, if I take the same code and put it in the got focus event, I get an
error, shown below after the code. The message is inserted, and the main
form is requeried, bu the add not popup does not close. If I hit ok on the
error message, then hit enter again, the add not popup then closes. My
intention is that the user can simply hit enter after typing the note rather
than having to hit the save button. Below is the code followed by the error.
I am using Access 2003 .ADP. Thank you.

'Code*****************************
Dim strSQL As String
Dim COMP_KEY As String

COMP_KEY = Forms!frmZMMR41_ZZMB52_Main!Child1.Form!txtCompKey.Value

strSQL = "INSERT INTO tblstorekeeper_notes(comp_key,note) " & _
"SELECT '" & COMP_KEY & "', '" & Replace(Me.txtNote, "'", "''")
& "'"

DoCmd.RunSQL strSQL

Forms!frmZMMR41_ZZMB52_Main!Child1.Form.Requery

DoCmd.Close acForm, "frmAddNote"

'Error message*******************
'This action can't be carried out while processing a form or report event.
 
S

Stefan Hoffmann

hi,

intention is that the user can simply hit enter after typing the note rather
than having to hit the save button. Below is the code followed by the error.
The Access event model does not allow that you carry out a
DoCmd.CloseForm in the Got Focus event.

In your case I would use the Key Pressed event. Set the Key Preview
property to True and add an event handler to the Key Pressed event, e.g.

Private Sub Form_KeyPressed(Key As Integer)

If Key = 13 Then
' Enter was pressed.
End If

End Sub


mfG
--> stefan <--
 
K

Kathy R.

From a user standpoint, you may want to rethink that. It's too easy
for a user to see that they're at the edge of the text/memo box, and
instead of letting wordwrap do its magic, hit the enter key to go to the
next line. Imagine their confusion and frustration when the popup box
suddenly closes when they weren't finished with their note yet.

Kathy R.
 
K

Kathy R.

Whoops, that was in reply to the original poster. It was not a comment
on your solution, which I realize was exactly what he asked for. I
don't claim to know enough about coding to comment on anyone's coding
suggestions here! Sorry if it came off that way.

Kathy
 
G

gsnidow via AccessMonster.com

Stefan, thanks for the tip, and Kathy, thanks for the good advice. I guess I
need to see what they want to do. If it was up to me, I would just put some
code to ask if they wanted to save, then they could just hit enter twice,
which, in my opinion, is faster than grabbing the mouse and clicking. In any
event, I appreciate the help.

Greg
From a user standpoint, you may want to rethink that. It's too easy
for a user to see that they're at the edge of the text/memo box, and
instead of letting wordwrap do its magic, hit the enter key to go to the
next line. Imagine their confusion and frustration when the popup box
suddenly closes when they weren't finished with their note yet.

Kathy R.
[quoted text clipped - 18 lines]
mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top