View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Garry Jones Garry Jones is offline
external usenet poster
 
Posts: 28
Default Cancel Exit on duplicate

wrote:

can not understand what you try to imply, need just
simple code of VBA.
thanks.


Okay I try again and I will simplify this.

With two textboxes.

Textbox1 contains a suggested value from a cell
Textbox2 contains a suggested value from another cell

The user form opens with Textbox1 Enabled=true and Textbox2
Enabled=false.

When the user tabs from Textbox1 my code checks to see if the user has
entered an accepted value.

I have a Public Function called chknow

This function contains this code extract to refuse value

MsgBox "Name Duplicate"
cancelclose = False
Chknow = True
CloseMode = 0
Exit Function

and this code to accept value

CloseMode = 1

I use TextBox1_BeforeUpdate to be able to reset the original value if
the user value is not accepted.

This contains
Cancel = Chknow(TextBox1)

I use TextBox1_Exit so that I can stop the user from leaving textbox1 if
the user value is not accepted.

This also contains
Cancel = Chknow(TextBox1)

I use TextBox1_KeyPress to check for user tab. When the user tabs I want
to set Enabled=False for Textbox1 and Enabled=True for Textbox2 and
place the user in Textbox2.

"TextBox1_KeyPress" contains

Select Case KeyAscii
Case 9: KeyAscii = 0: ntl 1
End Select

It sends 1 to a routine called ntl.

Somewhere in "ntl" I need to run the chknow function to see if the user
can leave textbox1. My problem is that the trap in chknow works and the
msgbox comes up if the value is not accepted, but because "keypress" is
checked before "exit" it is allowing the user to exit textbox1 even when
I don't want that to happen.

I think I have something very simple wrong, but I can't put my finger on
it.

Garry Jones
Sweden