curious question about 'onfocus'

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

Guest

Is it possible to stop someone from creating a new record if the cursor is
put into a new record.

The reason I ask is that I have three buttons which replicates the previous
record (each button does something slightly different), but it also
calculates the new date. I don't want a person to try to create a new record
without pressing one of these buttons.

I hope that makes sense!

thanks.
 
Hi,

Have you tried disabling the Allow Additions form property? Otherwise there
is a NewRecord property that you could test but I don't know when in the
cycle this property is set.

Regards,

Rod
 
Thanks for the reply,

Both the "allow additions" property and the "NewRecord" property are a bit
difficult to deal with. I came up with a compromise.

Private Sub Form_Current()

If Me.NewRecord Then
DoCmd.GoToRecord , , acLast

End If

End Sub

Using this I can include the blank row and stop the user from entering data
without clicking on one of the buttons first.
 
You could disable the built-in navigation buttons, then create your own
navigation buttons leaving out a New Record button and disabling the Next
button if you are at the last record. In this code cmdPrev, cmdNext, etc.
are the names of the navigation buttons.

'Enable navigation buttons only when there are records available
Me.cmdPrev.Enabled = Not Me.CurrentRecord = 1
Me.cmdFirst.Enabled = Not Me.CurrentRecord = 1
Me.cmdNext.Enabled = (Me.CurrentRecord = 1 And Me.Recordset.RecordCount
Or Me.CurrentRecord < Me.Recordset.RecordCount
Me.cmdLast.Enabled = Not (Me.cmdNext.Enabled = False)

You can combine this with Stephen Lebans fine utility for disabling the
ability to use the mouse scroll wheel to naviagate records:
http://www.lebans.com/mousewheelonoff.htm

Now the only way to get to a new record is to use your duplication buttons.
 
That'll work, and it's simple. I was just doubtful if NewRecord was set
early enough in the cycle; it obviously is.

Rod
 
scubadiver said:
Thanks for the reply,

Both the "allow additions" property and the "NewRecord" property are
a bit difficult to deal with. I came up with a compromise.

Private Sub Form_Current()

If Me.NewRecord Then
DoCmd.GoToRecord , , acLast

End If

End Sub

Using this I can include the blank row and stop the user from
entering data without clicking on one of the buttons first.

It seems a somewhat roundabout way to go about it. Why show the user a
blank record that they can't click in? But if you set AllowAdditions to
No in the design view, set it to True in your button event procedures,
and then set it to False again in the form's AfterInsert event, you
should be able to control it properly. If that exact logic doesn't
work -- as it might not, depending on what your buttons do -- some
tweaking of it ought to make things work nicely.
 
Back
Top