Simple code

  • Thread starter Thread starter aMack
  • Start date Start date
A

aMack

There are 2 data fields that i am trying to have populate with a time if null:

Private Sub DriverTimeLeg1_GotFocus()
If IsNull(Me.DriverTimeLeg1) Then
Me.DriverTimeLeg1 = Time
Cancel = True
End If
End Sub

This works!

I have a second field [DriverTimeLeg2] but the "Gotfocus" will not accept
the code.

Both are Formatted as "Short Time"


When entering the Code editor the second field shows up as:

Private Sub Text215_GotFocus()

Any Ideas?
 
Hi aMack

Check the Name property of your second textbox. I think you will find it is
"Text215". Change this to "DriverTimeLeg2" and all should be well.

Also, get rid of the Cancel=True line. The GotFocus event cannot be
cancelled, so its event procedure has no Cancel argument. I'm surprised the
code even compiles because of this. It can only be because you are missing
"Option Explicit" at the top of your module. EVERY module you write should
have this line at the top!
 
--
A MACKENZIE, CMA, MBA


Graham Mandeno said:
Hi aMack

Check the Name property of your second textbox. I think you will find it is
"Text215". Change this to "DriverTimeLeg2" and all should be well.

Also, get rid of the Cancel=True line. The GotFocus event cannot be
cancelled, so its event procedure has no Cancel argument. I'm surprised the
code even compiles because of this. It can only be because you are missing
"Option Explicit" at the top of your module. EVERY module you write should
have this line at the top!
--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand


aMack said:
There are 2 data fields that i am trying to have populate with a time if
null:

Private Sub DriverTimeLeg1_GotFocus()
If IsNull(Me.DriverTimeLeg1) Then
Me.DriverTimeLeg1 = Time
Cancel = True
End If
End Sub

This works!

I have a second field [DriverTimeLeg2] but the "Gotfocus" will not accept
the code.

Both are Formatted as "Short Time"


When entering the Code editor the second field shows up as:

Private Sub Text215_GotFocus()

Any Ideas?

Thanks - that did it.
 
Back
Top