tab order problem after vba code

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

Guest

hi everybody;

thanx in advance for your time...
question is,

Private Sub LeiDrop_LostFocus()

Dim ldrop As String
Dim kur As String
Dim uskars As String

ldrop = Forms!Currency!WinLoss2!LeiDrop.Text

Forms!Currency!Currency.SetFocus
kur = Forms!Currency!Currency.Text

uskars = ((ldrop) / (kur))

Forms!Currency!WinLoss2!LeiDrop.SetFocus
If Forms!Currency!WinLoss2!LeiDrop.Text = True Then
Forms!Currency!WinLoss2!LeiDrop = uskars
End If

Forms!Currency!WinLoss2!LeiOtherIn.SetFocus

End Sub

after this vba code, cursor is focusing "Currency" box instead of "LeiOtherIn"
how can I resolve this problem ????
 
suggest you don't refer to the Text property of the controls. that way you
won't need to keep moving the focus from control to control. instead, refer
to the Value property of each control. since that's the "default" property,
you don't have to explicitly refer to it. also, it looks like you have a
main form called Currency, and a subform called WinLoss2, and the code is
running in the subform. if this is correct, you don't have to use the full
form syntax to refer to the controls. instead, try

Private Sub LeiDrop_LostFocus()

Dim ldrop As String
Dim kur As String
Dim uskars As String

ldrop = Me!LeiDrop
kur = Me.Parent!Currency
uskars = (ldrop / kur)

If Me!LeiDrop = True Then
Me!LeiDrop = uskars
End If

Me!LeiOtherIn.SetFocus

End Sub

or simply use

Private Sub LeiDrop_LostFocus()

If Me!LeiDrop = True Then
Me!LeiDrop = (Me!LeiDrop / Me.Parent!Currency)
End If

Me!LeiOtherIn.SetFocus

End Sub

hth
 
taco said:
Private Sub LeiDrop_LostFocus()

Dim ldrop As String
Dim kur As String
Dim uskars As String

ldrop = Forms!Currency!WinLoss2!LeiDrop.Text

Forms!Currency!Currency.SetFocus
kur = Forms!Currency!Currency.Text

uskars = ((ldrop) / (kur))

Forms!Currency!WinLoss2!LeiDrop.SetFocus
If Forms!Currency!WinLoss2!LeiDrop.Text = True Then
Forms!Currency!WinLoss2!LeiDrop = uskars
End If

Forms!Currency!WinLoss2!LeiOtherIn.SetFocus

End Sub

after this vba code, cursor is focusing "Currency" box instead of "LeiOtherIn"
how can I resolve this problem ????


By the time the LostFocus event fires, the focus is already
being moved to the next item, so your set focus is
superceded when the procedure exits. Try using the
AfterUpdate event instead.

Your object references are confusing, First, the reference
ldrop = Forms!Currency!WinLoss2!LeiDrop.Text
may work in your version of Access, but it is not guaranteed
in all versions. It should be:
ldrop = Forms!Currency!WinLoss2.Form!LeiDrop.Text
However, that is going the long way around to get the text
in the LeiDrop text box. Instead of going throungh the main
form to get to the subform control and the form object in
the subform control, you can just refer to the code's form
object:
ldrop = Me.LeiDrop.Text
The use of Me is optional, but it does help distinguish
between control/field names and VBA variable names:
ldrop = LeiDrop.Text

Although Access usually unravels it correctly, your use of
the .Text property is not doing what you want. You should
be using the .Value property instead:
ldrop = Me.LeiDrop.Value
or just
ldrop = LeiDrop.Value
Even if you are getting the correct result from the .Text
property, the .Value property does not require the focus and
since it's the default property, you do not have to
explicity use the property name:
ldrop = Me.LeiDrop

Combining all that, you procedure can be more like:

Private Sub LeiDrop_AfterUpdate()
Dim ldrop As String
Dim kur As String
Dim uskars As String

ldrop = Me.LeiDrop
kur = Parent.Currency
uskars = ldrop / kur

If Me.LeiDrop = True Then
Me.LeiDrop = uskars
End If

Me.LeiOtherIn.SetFocus
End Sub

The logic in the procedure makes no sense to me. You are
using the value of LeiDrop in a calculation and then the If
statement checks it for logical True???
 
Back
Top