toggling allow deletions property of form in onclick event

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

Guest

i have a form whose deletions property was natively turned off in the forms
property window. i currently wish to allow grant certain users the ability to
delete records (e.g. subject to their username). i created a command button
using the wizard that i've placed upon the form which has no effect. i think
the thing to do is using vba to place a line of code atop the vba which
enables the delete property and then at the bottom of it to reverse the
aforesaid's. can't quite seem to find the reference in the vba help doc's.

anyone?
 
Ted said:
i have a form whose deletions property was natively turned off in the
forms property window. i currently wish to allow grant certain users
the ability to delete records (e.g. subject to their username). i
created a command button using the wizard that i've placed upon the
form which has no effect. i think the thing to do is using vba to
place a line of code atop the vba which enables the delete property
and then at the bottom of it to reverse the aforesaid's. can't quite
seem to find the reference in the vba help doc's.

What code have you actually tried? Please post it.

When you say "username", do you mean the the name used when logging into
Access, as returned by CurrentUser(), or the Windows user name, or some
other user name you have collected somehow?

Do you want to be able to allow deletions automatically for these users,
or do you want them to have to click your button? Do you want your
button to just delete the current record, or to turn AllowDeletions on
until some further action is taken to turn the property back off again?

If you would be so good as to describe how you want the user to interact
with the form, as regards deletions, we can probably tell you how to
make it happen.
 
hi,

when i create a 'delete record' cmdbutton using the 'wizard' the resulting
code for 'onclick' is as follows:

Private Sub Command311_Click()
On Error GoTo Err_Command311_Click

'new code to go here

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

'ditto

Exit_Command311_Click:
Exit Sub

Err_Command311_Click:
MsgBox Err.Description
Resume Exit_Command311_Click

End Sub

as i mentioned, the 'Allow Deletions' property of this form is 'No'. what i
think would do the trick would be some command just before and after the
above that would temporarily override the 'No' property long enough for the
said code to do its job and then the code that would reset the 'Allow
Deletions' property to 'No' once more.

i have the username thing under control, so don't worry about that part.

much obliged for the interest. looking forward to hearing from you.
 
Ted said:
hi,

when i create a 'delete record' cmdbutton using the 'wizard' the
resulting code for 'onclick' is as follows:

Private Sub Command311_Click()
On Error GoTo Err_Command311_Click

'new code to go here

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

'ditto

Exit_Command311_Click:
Exit Sub

Err_Command311_Click:
MsgBox Err.Description
Resume Exit_Command311_Click

End Sub

as i mentioned, the 'Allow Deletions' property of this form is 'No'.
what i think would do the trick would be some command just before and
after the above that would temporarily override the 'No' property
long enough for the said code to do its job and then the code that
would reset the 'Allow Deletions' property to 'No' once more.

i have the username thing under control, so don't worry about that
part.

much obliged for the interest. looking forward to hearing from you.

The central code would be something like this:

'----- start of revised code -----
Private Sub Command311_Click()
On Error GoTo Err_Command311_Click


If (user is permitted to delete records) Then ' your logic here

' Turn on permission to delete.
Me.AllowDeletions = True

' Delete the current record (replaces old DoMenuItem syntax).
RunCommand acCmdDeleteRecord

End If

Exit_Command311_Click:
Me.AllowDeletions = False ' turn off deletions again
Exit Sub

Err_Command311_Click:
' Ignore "error" if user cancels delete; otherwise
' show the error message.
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_Command311_Click

End Sub
'----- end of revised code -----
 
i 'knew' it had to be something like that, but i couldn't recollect the
"Me.AllowDeletions = True" part. tganks dirk.....couldn't have done it w/o
you.

ted
 
Back
Top