Adding code to navigation buttons

  • Thread starter Thread starter reidarT
  • Start date Start date
R

reidarT

Is it possible to add code when the user clicks the Add-button on the built
in navigation buttons?
I have to activeXDatecontrols that should be filled with today if they are
empty.
reidarT
 
Hi reidarT,

I suggest that solving your requirement by use of the navigation button is
not the way to go; anyway the answer to your question is, 'No.'

Explore using the form's On Current event. What you need is some way of
detecting that the form being displayed is that to add a new record. Perhaps
you could test the values of one or both of your date controls. (A test I
have used in the past is to determine whether the value of an Autonumber
field is null.) Once you are certain that it is an 'add new record' form then
poke today's date in both controls. Do all this within the On Current event.

One word of warning. If your date controls are bound to fields in an
underlying recordset then having altered their values Access will attempt to
save the record when you exit that form (or move to another record). Most of
the time this is what you want but suppose you clicked the navigation button
by mistake; you have to provide some sort of cancel/don't save functionality.

Regards,

Rod
 
I believe you are making it harder than it has to be. I don't know what date
controls you are using, but they should allow a Default Value.
If they do, just set it to Date()
If they do not, use the form's current event. You can tell if it is a new
record or not and load your controls like this:

If Me.NewRecord Then
Me.DateCtl1 = Date
Me.DateCtl2 = Date
End If
 
Good grief! How long have I been using Access and I am not aware of the
NewRecord property? Just goes to show you can learn something new every day.

Thanks Klatuu
 
Back
Top