From: gsnidow via AccessMonster.com on
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.

--
Message posted via http://www.accessmonster.com

From: Stefan Hoffmann on
hi,

On 25.02.2010 18:32, gsnidow via AccessMonster.com wrote:
> 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 <--
From: Kathy R. on
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.

Stefan Hoffmann wrote:
> hi,
>
> On 25.02.2010 18:32, gsnidow via AccessMonster.com wrote:
>> 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 <--
From: Stefan Hoffmann on
hi Kathy,

On 26.02.2010 18:37, Kathy R. wrote:
> From a user standpoint, you may want to rethink that.
No, I won't. It's what the OP wants to do...


mfG
--> stefan <--
From: Kathy R. on
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

Stefan Hoffmann wrote:
> hi Kathy,
>
> On 26.02.2010 18:37, Kathy R. wrote:
>> From a user standpoint, you may want to rethink that.
> No, I won't. It's what the OP wants to do...
>
>
> mfG
> --> stefan <--