Getting the focus to stay in a field

D

DubboPete

Hi all,

I have tried error trapping a field, whereby if the value of [field2] does
not match [field1] then it should exit sub and stay there for correction.

It (A2K) don't want to do that, and currently I am having to use the
'gotFocus' event of the next field [field3] to force it back to [field2]!

<basic code snippet... Events... on dirty = true, or AfterUpdate, or Exit>

If me.[field2] <> me.[field1] Then
msgbox "yada yada.", vbInformation
me.[field2].setfocus
Exit Sub
End if
</snippet>

The dang thing moves to [field3] regardless, so at the mo I have [field3]
checking the same values, and...

<snip2>
Private Sub Field3_gotfocus()
If me.[field2] <> me.[field1] Then
me.[field2].setfocus
End If
</snip2>

Code above is not copied direct from the event, hence the irregularities
with me and Me instances.... but it hopefully gives the general idea of what
I am trying to achieve...

Is there any reason why the focus cannot stay with [field2]?

your list's own 17th century goat-herder,
DubboPete
 
T

tina

try adding the validation to the control's BeforeUpdate event, as

Private Sub Field2_BeforeUpdate(Cancel As Integer)

If Not (Me!Field2 = Me!Field1) Then
msgbox "yada yada.", vbInformation
Cancel = True
End If

End Sub

hth
 
D

DubboPete

thanks Tina,

will keep u informed when I get back to work in the morning, and i get to
try it...

Pete the goat herder

tina said:
try adding the validation to the control's BeforeUpdate event, as

Private Sub Field2_BeforeUpdate(Cancel As Integer)

If Not (Me!Field2 = Me!Field1) Then
msgbox "yada yada.", vbInformation
Cancel = True
End If

End Sub

hth


DubboPete said:
Hi all,

I have tried error trapping a field, whereby if the value of [field2]
does
not match [field1] then it should exit sub and stay there for correction.

It (A2K) don't want to do that, and currently I am having to use the
'gotFocus' event of the next field [field3] to force it back to [field2]!

<basic code snippet... Events... on dirty = true, or AfterUpdate, or Exit>

If me.[field2] <> me.[field1] Then
msgbox "yada yada.", vbInformation
me.[field2].setfocus
Exit Sub
End if
</snippet>

The dang thing moves to [field3] regardless, so at the mo I have [field3]
checking the same values, and...

<snip2>
Private Sub Field3_gotfocus()
If me.[field2] <> me.[field1] Then
me.[field2].setfocus
End If
</snip2>

Code above is not copied direct from the event, hence the irregularities
with me and Me instances.... but it hopefully gives the general idea of what
I am trying to achieve...

Is there any reason why the focus cannot stay with [field2]?

your list's own 17th century goat-herder,
DubboPete
 
D

DubboPete

worked fine Tina,

thanks for your help

Pete

tina said:
try adding the validation to the control's BeforeUpdate event, as

Private Sub Field2_BeforeUpdate(Cancel As Integer)

If Not (Me!Field2 = Me!Field1) Then
msgbox "yada yada.", vbInformation
Cancel = True
End If

End Sub

hth


DubboPete said:
Hi all,

I have tried error trapping a field, whereby if the value of [field2]
does
not match [field1] then it should exit sub and stay there for correction.

It (A2K) don't want to do that, and currently I am having to use the
'gotFocus' event of the next field [field3] to force it back to [field2]!

<basic code snippet... Events... on dirty = true, or AfterUpdate, or Exit>

If me.[field2] <> me.[field1] Then
msgbox "yada yada.", vbInformation
me.[field2].setfocus
Exit Sub
End if
</snippet>

The dang thing moves to [field3] regardless, so at the mo I have [field3]
checking the same values, and...

<snip2>
Private Sub Field3_gotfocus()
If me.[field2] <> me.[field1] Then
me.[field2].setfocus
End If
</snip2>

Code above is not copied direct from the event, hence the irregularities
with me and Me instances.... but it hopefully gives the general idea of what
I am trying to achieve...

Is there any reason why the focus cannot stay with [field2]?

your list's own 17th century goat-herder,
DubboPete
 

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