Simple code

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?
 
G

Graham Mandeno

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!
 
L

Linq Adams via AccessMonster.com

I wondered about that also, and I expect your explanation is correct. I've
never understood why "Option Explicit" isn't the Default.
 
A

aMack

--
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.
 

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