setting focus

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

Guest

I have an unbound control in the head of a form to select an item. I put a
code on the AfterUpdate property to pass the focus to a control in the body
of the form:

Me.DeliveryDate.Setfocus

I always get an error message that the focus cannot be passed to this
control. I changed "Me" to the full description of the form, no result. There
is no explanation why. Could u figure out what can be wrong?

Thanks in advance for your kind assistance.
 
It works fine for me! Is the control disabled?

In any case, I think you're better to use the Tab Order, to do it
automatically.

Open the form in design view, right-click and select Tab Order from the
context menu.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
The control is enabled. The Tab order does not help since the unbound control
is in the head, the other control in the body section of the form.

In the meantime I realized that the problem is caused by the fact that there
is an event procedure on the GotFocus property of the control I want to pass
the focus to. This two contradict each other somehow. I might put the secont
procedure on another event following the GotFocus event but I do not yet know
which one. Any idea?
 
That depends on what that procedure does. What does it do?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 
Since we get forecasts of future orders for weekly deliveries the code looks
for the last date for the item in question and adds 7 days to the last date
so the user does not have to fill in the date field:

Private Sub DelDate_GotFocus()

Set db = CurrentDb
Set rs = db.OpenRecordset("Forecasts", dbOpenDynaset)
cond = Me.ProdSelect

With rs
..MoveLast
..FindLast "[ItemCode] ='" & cond & "'"
If .NoMatch = False Then
felt = rs![DelDate]
Me.DelDate = felt + 7
Me.Quantity.SetFocus
Else
Me.DelDate.SetFocus
End If
rs.Close
End With

End Sub

Thanks for your efforts.
 
Add a secondary Else statement to set the Focus where you want in the line of
code you posted.

Coldeyes said:
Since we get forecasts of future orders for weekly deliveries the code looks
for the last date for the item in question and adds 7 days to the last date
so the user does not have to fill in the date field:

Private Sub DelDate_GotFocus()

Set db = CurrentDb
Set rs = db.OpenRecordset("Forecasts", dbOpenDynaset)
cond = Me.ProdSelect

With rs
.MoveLast
.FindLast "[ItemCode] ='" & cond & "'"
If .NoMatch = False Then
felt = rs![DelDate]
Me.DelDate = felt + 7
Me.Quantity.SetFocus
Else
Me.DelDate.SetFocus
End If
rs.Close
End With

End Sub

Thanks for your efforts.

Graham R Seach said:
That depends on what that procedure does. What does it do?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
I'm a little confused here. You first referred to the control as
"Me.DeliveryDate", then later as "Me.DelDate". That might be the problem.

In any case, why set the focus to a control that already has the focus?

As for your code, you might do away with the FindFirst method altogether by
being a bit mmore specific with your query:

sSQL = "SELECT TOP 1 DelDate " & _
"FROM Forecasts " & _
"WHERE ItemCode = """ & Me.ProdSelect & """ " & _
"ORDER BY DelDate DESC"

Set db = CurrentDb
Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)
If rs.AbsolutePosition > -1 Then
'The record was found...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Coldeyes said:
Since we get forecasts of future orders for weekly deliveries the code
looks
for the last date for the item in question and adds 7 days to the last
date
so the user does not have to fill in the date field:

Private Sub DelDate_GotFocus()

Set db = CurrentDb
Set rs = db.OpenRecordset("Forecasts", dbOpenDynaset)
cond = Me.ProdSelect

With rs
.MoveLast
.FindLast "[ItemCode] ='" & cond & "'"
If .NoMatch = False Then
felt = rs![DelDate]
Me.DelDate = felt + 7
Me.Quantity.SetFocus
Else
Me.DelDate.SetFocus
End If
rs.Close
End With

End Sub

Thanks for your efforts.

Graham R Seach said:
That depends on what that procedure does. What does it do?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top