SetFocus not working

  • Thread starter Thread starter Junior
  • Start date Start date
J

Junior

Hi - what am i doing wrong with the following code - it works except focus
does not return to [txtDteRet]?

If Not (dtReturnd >= dtIssued) Then
MsgBox "The date returned cannot be earlier than date issued"
Me.txtDteRet.SetFocus
Me!txtDteRet = Null
Exit Sub
End If
 
The code looks fine but maybe you have some other code that is running when
Me.txtDteRet is reset to Null.
Try setting the focus after resetting it to Null

Me.txtDteRet = Null
Me.txtDetRet.SetFocus

Cheers,
Peter
 
Junior said:
Hi - what am i doing wrong with the following code - it works except focus
does not return to [txtDteRet]?

If Not (dtReturnd >= dtIssued) Then
MsgBox "The date returned cannot be earlier than date issued"
Me.txtDteRet.SetFocus
Me!txtDteRet = Null
Exit Sub
End If

Where is that code? You can not reset the focus in some
events. That kind of check is usually done in the control's
BeforeUpdate event and instead of setting the focus, set the
procedure's Cancel argument to True.

Sub dtReturnd_BeforeUpdate(Cancel As Integer)
If Not (dtReturnd >= dtIssued) Then
MsgBox "The date returned cannot be earlier than date
issued"
Me!txtDteRet.Undo
Cancel = True
Exit Sub
End If
 
Marshall - the code is called in the after update event
is that the problem??
Marshall Barton said:
Junior said:
Hi - what am i doing wrong with the following code - it works except focus
does not return to [txtDteRet]?

If Not (dtReturnd >= dtIssued) Then
MsgBox "The date returned cannot be earlier than date issued"
Me.txtDteRet.SetFocus
Me!txtDteRet = Null
Exit Sub
End If

Where is that code? You can not reset the focus in some
events. That kind of check is usually done in the control's
BeforeUpdate event and instead of setting the focus, set the
procedure's Cancel argument to True.

Sub dtReturnd_BeforeUpdate(Cancel As Integer)
If Not (dtReturnd >= dtIssued) Then
MsgBox "The date returned cannot be earlier than date
issued"
Me!txtDteRet.Undo
Cancel = True
Exit Sub
End If
 
Junior said:
Marshall - the code is called in the after update event
is that the problem??

Most actions that cause the edited text in a control to be
updated have already started the process of moving the
focus, so it's too late for your code to change its mind.

Try the sample code I provided earlier.
--
Marsh
MVP [MS Access]


Junior said:
Hi - what am i doing wrong with the following code - it works except focus
does not return to [txtDteRet]?

If Not (dtReturnd >= dtIssued) Then
MsgBox "The date returned cannot be earlier than date issued"
Me.txtDteRet.SetFocus
Me!txtDteRet = Null
Exit Sub
End If
"Marshall Barton" wrote
Where is that code? You can not reset the focus in some
events. That kind of check is usually done in the control's
BeforeUpdate event and instead of setting the focus, set the
procedure's Cancel argument to True.

Sub dtReturnd_BeforeUpdate(Cancel As Integer)
If Not (dtReturnd >= dtIssued) Then
MsgBox "The date returned cannot be earlier than date
issued"
Me!txtDteRet.Undo
Cancel = True
Exit Sub
End If
 
Back
Top