Clearing a textbox after Cancelling

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

Hello,

I have an unbound control on a form with the following code:

Private Sub FullName_BeforeUpdate(Cancel As Integer)

With Me.RecordsetClone
.FindFirst "[FullName] = '" & Me.ActiveControl & "'"
If Not .NoMatch Then
MsgBox Me.ActiveControl & " is already in use. Choose another Full Name
or cancel!"
Cancel = True
FullName.Undo
End If

End With

End Sub

After the Cancel I want the textbox cleared. The Undo of the textbox
doesn't accomplish this.

Thank you for any help and God Bless,

Mark A. Sam
 
Bruce,

Using TextBoxName = Me.TextBoxName.Tag doesn't work. I had already tried
setting the value to Null, and got the same error. Using the AfterUpdate
isn't useful becuase the focus goes to the next field. The undo method
highlights the control, so I'll go with that. It allows tabbing to the next
control, keeping the incorrect value, but I have another check on the Add
button. Not the best way to go, but this form will be seldom used.

Thank you and God Bless,

Mark



BruceM via AccessMonster.com said:
I think you cannot use Undo for an unbound control. As a workaround you
can
set the Tag property of the control to a zero-length string, and it the
Before Update event rather than Me.TextBoxName.Undo you can use Me.
TextBoxName = Me.TextBoxName.Tag

You can also use this idea to set the Tag property in the After Update
event
for the control, and revert to the Tag value (the previous search value)
in
the Before Update event if the search is not successful.
Hello,

I have an unbound control on a form with the following code:

Private Sub FullName_BeforeUpdate(Cancel As Integer)

With Me.RecordsetClone
.FindFirst "[FullName] = '" & Me.ActiveControl & "'"
If Not .NoMatch Then
MsgBox Me.ActiveControl & " is already in use. Choose another Full
Name
or cancel!"
Cancel = True
FullName.Undo
End If

End With

End Sub

After the Cancel I want the textbox cleared. The Undo of the textbox
doesn't accomplish this.

Thank you for any help and God Bless,

Mark A. Sam
 
John,

I tried both .SetFocus and .GoToControl and neither worked. The .SetFocus
gave a message that I need to save the field and .GoToControl said that the
Action or Method was not available at this time.

God Bless,

Mark

J_Goddard via AccessMonster.com said:
Oops - I have an error in the code - it should be like this:

Private Sub FullName_AfterUpdate
With Me.RecordsetClone
.FindFirst "[FullName] = '" & Me.ActiveControl & "'"
If Not .NoMatch Then
MsgBox Me.ActiveControl & " is already in use. Choose another Full
Name.
"
doCmd.GotoControl "SomeOtherControl"
doCmd.GotoControl "FullName"
me!FullName=""
End If
End With
End Sub

with me!FullName="" inside the IF....

Sorry 'bout that!

John


J_Goddard said:
Hi -

You can use the After Update event of the Textbox, using the DoCmd.
GotoControl method. Using just DoCmd.gotocontrol "Textbox", won't work,
as
you have seen, but if you goto some OTHER control, then go back to
Textbox,
it works! So, you get something like this:

Private Sub FullName_AfterUpdate
With Me.RecordsetClone
.FindFirst "[FullName] = '" & Me.ActiveControl & "'"
If Not .NoMatch Then
MsgBox Me.ActiveControl & " is already in use. Choose another Full
Name.
"
doCmd.GotoControl "SomeOtherControl"
doCmd.GotoControl "FullName"
End If
me!FullName=""
End With
End Sub

A bit of a kluge - but it works!

John
[quoted text clipped - 14 lines]
Mark A. Sam

--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via AccessMonster.com
 
This worked. It gave an error, which I handled with Resume Next.

Private Sub FullName_BeforeUpdate(Cancel As Integer)
On Error Resume Next

With Me.RecordsetClone
.FindFirst "[FullName] = '" & Me.ActiveControl & "'"
If Not .NoMatch Then
MsgBox Me.ActiveControl & " is already in use. Choose another Full Name
or cancel!"
Cancel = True
FullName.Text = ""
End If

End With

End Sub
 
Back
Top