Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i create records that can not be deleted 1

Status
Not open for further replies.

miketamp

Technical User
Jan 28, 2005
20
GR
hi
i have a table called "tblone"
i would like only the first 20 records to be able not to be deleted by the user.and the rest records behave as normal recods in a normal table.
can you please help me?
thanx...
 
This technique only works if your users are accessing records via a form, and cannot access the table directly.

-- Add a yes/no field to your table. Call this ProtectFlag
-- Do not include this field on your form, so the users cannot get to it.
-- Set this field to 'True' via the table, on the records which must not be deleted.
-- Add this code to the Delete event of your form:

Code:
    If Me.ProtectFlag = True then
        MsgBox "You cannot delete this record", vbExclamation
        DoCmd.CancelEvent
    End If

Now, users will be able to delete records as usual, unless they have your hidden 'ProtectFlag' field set.

Other thoughts ...
-- The 'undeletable' records can now occur anywhere in the table, which may be useful.
-- If you write any queries or VBA code which deletes records, remember to include a test for the 'ProtectFlag' field value in the query or code.

I hope that this helps.

Bob Stubbs
 
This looks highly likely that you have not normalised your database. What is different about the 20 records?

 
propably as i am new in databases.but i didn't find another way to create many combo boxes in a form depented to other combo boxes. because the only way that i find to do that is a "select" comand at the "rowsource" of eatch combobox.So i could make seperate tables for each combo or one table with many fields,one field per combobox. i decide to do the second.and i don't know if it is the right but till now works perfect.It's too complicate to explain you exactly what i want to create.but thanx anyway...
 
hi bobstubbs
i use the code you sed to me but when i'm trying to delete a record i have a visual basic compile error : "method or data member not found".
why is that?
 
Hi it's me again
i did this corection to the code tha you give me and working fine:

Private Sub Form_Delete(Cancel As Integer)
Set rs = CurrentDb.OpenRecordset("dieta_tbl")
If rs!protectFlag = True Then
MsgBox "You cannot delete this record!", vbExclamation
DoCmd.CancelEvent
End If
End Sub


that is because the "protectflag" locates in the table and not in the form. So you must not use "me." but you must choose the correct table
thanx...
 
Sorry for the delay, and the mistake ...

I should have said:

Add the ProtectFlag field to your form, but set its 'Visible' property to 'False' so that users cannot see it.

If you do this, the original syntax will work.


Bob Stubbs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top