Help for form/subform record lock and confirmation

  • Thread starter Thread starter Veli Izzet
  • Start date Start date
V

Veli Izzet

Hi all,

In my project I have a form/subform for sales/sales details. Subform is
in datasheet view.

I cannot lock the records in the subform so users may inadvertently
delete or modify the records in the subform.

I want to be able to lock the records, and have a confirmation box show
up both for deleting and updating the records.

Thanks for any help..

Veli Izzet
 
For an edit-confirmation dialog, use the BeforeUpdate event of the form (not
control).

This kind of thing:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
If MsgBox("Save", vbYesNo+vbDefaultButton2, "Confirm edit") = vbNo
Then
Cancel = True
Me.Undo
End If
End If
End Sub

You should already get a delete confirmation, unless you have turned it off.
If you want to modify the message, you can do so in Form_BeforeDelConfirm.

If you want to prevent accidental edits by locking the form and subform
until the user unlocks it, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html
 
Thanks Allen,

Actually I was just blooking at your tip:-)

The only question: Does it also work on subforms with datasheet view?

Regards,
 
The only problem is:

When getting to another form, the state of cmdLock does not change.

For one form I used "=LockBoundControls([Form];True)" on the onCurrent
control of the form, and it worked.

In another case, the form already had another procedure on the onCurrent
control, so the problem remains.

Regards
 
If you are using an Event Procedure already in Form_Current, you could add
this line to the top of your existing code:
Call LockBoundControls(Me, True)

If you have code that dirties the record in Form_Current (assigning a value
to a bound control), the code may not work as expected after that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.
\
Veli Izzet said:
The only problem is:

When getting to another form, the state of cmdLock does not change.

For one form I used "=LockBoundControls([Form];True)" on the onCurrent
control of the form, and it worked.

In another case, the form already had another procedure on the onCurrent
control, so the problem remains.

Regards


Allen said:
Sure: the properties can be set regardless of the view of the subform.
 
I added the line to the bottom of the code, and it seems to work (did
not do extensive testing).

Thanks anyhow
 
Back
Top