setfocus back in an exit event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

in an exit event, I check the field value, if something wrong with the data
entered, I need to set the focus stayed at the control until user entered a
valid data, I wrote like this:

Private Sub SetNum1_Exit(Cancel As Integer)

Dim Brandcd As Variant
Dim Bcdstr As String

If Not IsNull(Forms!test!SetNum1) Then
Brandcd = DLookup("SegmentCode", "dbo_Item", "[ItemNumber] =
Forms!test!SetNum1")
If Not IsNull(Brandcd) Then
Bcdstr = Brandcd
If Bcdstr <> Forms!test!SegmentCode Then
Forms!test!SetNum1.BackColor = 16751052
MsgBox ("Segment Code is not consistent")
Forms!test!SetNum1.SetFocus
Exit Sub
End If
End If
End If
End Sub

but after the event, the focus still moves on to the next control, how can I
keep it?

any help would be great, thanks a lot in advance!
 
See below, you need to move the code to the Before Update event. The Exit
event fires whether you make any changes to the data or not and the field has
already been updated before the Exit event fires if there were changes. The
usual way to do this is in the Before Update event. That is what this event
is for, to validate data prior to the update. Note I changed your SetFocus
line to Cancel = True. That causes the update to cancel and the focus stays
in the control.
 
Hi Klatuu,

It works! Thank you so very much! I really appreciate your help!

Have a nice day!


Klatuu said:
See below, you need to move the code to the Before Update event. The Exit
event fires whether you make any changes to the data or not and the field has
already been updated before the Exit event fires if there were changes. The
usual way to do this is in the Before Update event. That is what this event
is for, to validate data prior to the update. Note I changed your SetFocus
line to Cancel = True. That causes the update to cancel and the focus stays
in the control.

lily said:
in an exit event, I check the field value, if something wrong with the data
entered, I need to set the focus stayed at the control until user entered a
valid data, I wrote like this:

Private Sub SetNum1_BeforeUpdate(Cancel As Integer)

Dim Brandcd As Variant
Dim Bcdstr As String

If Not IsNull(Forms!test!SetNum1) Then
Brandcd = DLookup("SegmentCode", "dbo_Item", "[ItemNumber] =
Forms!test!SetNum1")
If Not IsNull(Brandcd) Then
Bcdstr = Brandcd
If Bcdstr <> Forms!test!SegmentCode Then
Forms!test!SetNum1.BackColor = 16751052
MsgBox ("Segment Code is not consistent")
Cancel = True
Exit Sub
End If
End If
End If
End Sub

but after the event, the focus still moves on to the next control, how can I
keep it?

any help would be great, thanks a lot in advance!
 
Of course it works! I wrote it.
You are very honored to have me assist you
:)

lily said:
Hi Klatuu,

It works! Thank you so very much! I really appreciate your help!

Have a nice day!


Klatuu said:
See below, you need to move the code to the Before Update event. The Exit
event fires whether you make any changes to the data or not and the field has
already been updated before the Exit event fires if there were changes. The
usual way to do this is in the Before Update event. That is what this event
is for, to validate data prior to the update. Note I changed your SetFocus
line to Cancel = True. That causes the update to cancel and the focus stays
in the control.

lily said:
in an exit event, I check the field value, if something wrong with the data
entered, I need to set the focus stayed at the control until user entered a
valid data, I wrote like this:

Private Sub SetNum1_BeforeUpdate(Cancel As Integer)

Dim Brandcd As Variant
Dim Bcdstr As String

If Not IsNull(Forms!test!SetNum1) Then
Brandcd = DLookup("SegmentCode", "dbo_Item", "[ItemNumber] =
Forms!test!SetNum1")
If Not IsNull(Brandcd) Then
Bcdstr = Brandcd
If Bcdstr <> Forms!test!SegmentCode Then
Forms!test!SetNum1.BackColor = 16751052
MsgBox ("Segment Code is not consistent")
Cancel = True
Exit Sub
End If
End If
End If
End Sub

but after the event, the focus still moves on to the next control, how can I
keep it?

any help would be great, thanks a lot in advance!
 
you know what, I'm very familiar with these words, one of my good friend
always say this to me after I thanked her... :-)

Klatuu said:
Of course it works! I wrote it.
You are very honored to have me assist you
:)

lily said:
Hi Klatuu,

It works! Thank you so very much! I really appreciate your help!

Have a nice day!


Klatuu said:
See below, you need to move the code to the Before Update event. The Exit
event fires whether you make any changes to the data or not and the field has
already been updated before the Exit event fires if there were changes. The
usual way to do this is in the Before Update event. That is what this event
is for, to validate data prior to the update. Note I changed your SetFocus
line to Cancel = True. That causes the update to cancel and the focus stays
in the control.

:

in an exit event, I check the field value, if something wrong with the data
entered, I need to set the focus stayed at the control until user entered a
valid data, I wrote like this:

Private Sub SetNum1_BeforeUpdate(Cancel As Integer)

Dim Brandcd As Variant
Dim Bcdstr As String

If Not IsNull(Forms!test!SetNum1) Then
Brandcd = DLookup("SegmentCode", "dbo_Item", "[ItemNumber] =
Forms!test!SetNum1")
If Not IsNull(Brandcd) Then
Bcdstr = Brandcd
If Bcdstr <> Forms!test!SegmentCode Then
Forms!test!SetNum1.BackColor = 16751052
MsgBox ("Segment Code is not consistent")
Cancel = True
Exit Sub
End If
End If
End If
End Sub

but after the event, the focus still moves on to the next control, how can I
keep it?

any help would be great, thanks a lot in advance!
 
lol, I guess I've been listeing to Mark Levine too much.

lily said:
you know what, I'm very familiar with these words, one of my good friend
always say this to me after I thanked her... :-)

Klatuu said:
Of course it works! I wrote it.
You are very honored to have me assist you
:)

lily said:
Hi Klatuu,

It works! Thank you so very much! I really appreciate your help!

Have a nice day!


:

See below, you need to move the code to the Before Update event. The Exit
event fires whether you make any changes to the data or not and the field has
already been updated before the Exit event fires if there were changes. The
usual way to do this is in the Before Update event. That is what this event
is for, to validate data prior to the update. Note I changed your SetFocus
line to Cancel = True. That causes the update to cancel and the focus stays
in the control.

:

in an exit event, I check the field value, if something wrong with the data
entered, I need to set the focus stayed at the control until user entered a
valid data, I wrote like this:

Private Sub SetNum1_BeforeUpdate(Cancel As Integer)

Dim Brandcd As Variant
Dim Bcdstr As String

If Not IsNull(Forms!test!SetNum1) Then
Brandcd = DLookup("SegmentCode", "dbo_Item", "[ItemNumber] =
Forms!test!SetNum1")
If Not IsNull(Brandcd) Then
Bcdstr = Brandcd
If Bcdstr <> Forms!test!SegmentCode Then
Forms!test!SetNum1.BackColor = 16751052
MsgBox ("Segment Code is not consistent")
Cancel = True
Exit Sub
End If
End If
End If
End Sub

but after the event, the focus still moves on to the next control, how can I
keep it?

any help would be great, thanks a lot in advance!
 

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

Similar Threads


Back
Top