Textbox OnChange event

M

Mark A. Sam

Hello,

On the KeyPress event of a textbox I assign variable iKeyAscii the value
KeyAscii

Private Sub Deduction_KeyPress(KeyAscii As Integer)

iKeyAscii = KeyAscii

End Sub

In the Change Event of the textbox I test for the value If iKeyAscii = 61.
It true it opens a form in Dialog mode.

Private Sub Deduction_Change()

If iKeyAscii = 61 Then
DoCmd.OpenForm "ClaimsDeductionCalc", , , , , acDialog
DoCmd.RunCommand acCmdUndo
End If

End Sub

The problem I am having is that when I close the form, it opens again.
When testing, I used a messagebox and the same thing occured, that then I
closed the messagebox it open a second time.

Can anyone tell me what this is happening and how to avoid it?

Thank you and God Bless,

Mark A. Sam
 
K

Ken Snell \(MVP\)

I believe the Undo action will cause the Change event to occur again, and
you didn't cancel out the KeyAscii value (set its value to 0) before you
call the Deduction_Change subroutine. And you should set the iKeyAscii value
to 0 in thie Deduction_Change subroutine before you open the form.
 
M

Mark A. Sam

Thank you Ken, Then solved it


Ken Snell (MVP) said:
I believe the Undo action will cause the Change event to occur again, and
you didn't cancel out the KeyAscii value (set its value to 0) before you
call the Deduction_Change subroutine. And you should set the iKeyAscii value
to 0 in thie Deduction_Change subroutine before you open the form.
 

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