I know this is a pretty general topic, but I hope no one will get mad at me for asking this question here. I have an application and because of how it will be used, I want to make sure it is set up in a way that has tight control over what records people can delete, and which combo values can be added to, or not.
This application is a SQL database, with an Access front-end, for data entry. The only Access "reporting" I do, is a sort of build your own report form, with listboxes for optional filtering, and 1 listbox for choosing which fields to select and group by. When the report is run, it is actually a query that appears in a subform object, so they can sort, re-filter, and copy to excel or email. The rest of the reporting is SSRS.
The main question I'm turning over is that there are 76 combos in this app. I used the following code to identify them and their row source:
Code:
Public Function getCombos()
On Error Resume Next
Dim obj As AccessObject, dbs As Object
Dim ctrl As Control
Dim frm As Form
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
DoCmd.OpenForm obj.Name, acDesign
For Each ctrl In Forms(obj.Name).Controls
If ctrl.ControlType = acComboBox Then
Debug.Print obj.Name & "^" & ctrl.Name & "^" & ctrl.RowSource
End If
Next ctrl
DoCmd.Close acForm, obj.Name, acSaveNo
Next obj
End Function
I am working through which ones a user should be able to "maintain", which I do through a universal maintenance form. Others have a row source from another database, and cannot be changed. The values are what they are, and I use a default message in the Not In List, to tell the user that info.
Now, I want to make sure in every place, that a user can clearly understand if they can delete a record or not. I don't want a messy database, so I want users to be able to clean up bad records. I don't want them to orphan records either.
So records, in terms of deleting might be: 1) a "sub" record, or one with no "sub" records to it 2) a list of values, which may be tied to multiple records 3) a record with 1 or more sub-records. If only one, it's not hard to check that. If there are multiple, I either need a control table to tell me which ones to check, or I have to hard code which ones to check
I used this sql query, to get all the relationships:
Code:
SELECT tr.name 'pTable'
--, cr.name 'pColumn',
,tp.name 'cTable'
--, cp.name 'cColumn', fk.name 'Index Name'
FROM sys.foreign_keys fk
LEFT JOIN sys.tables tp ON fk.parent_object_id = tp.object_id
LEFT JOIN sys.tables tr ON fk.referenced_object_id = tr.object_id
LEFT JOIN sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id
LEFT JOIN sys.columns cp ON fkc.parent_column_id = cp.column_id AND fkc.parent_object_id = cp.object_id
LEFT JOIN sys.columns cr ON fkc.referenced_column_id = cr.column_id AND fkc.referenced_object_id = cr.object_id
order by tr.name
The reason I have to check them all in the VBA, is that if I let it just send the request (delete) to SQL, I will end up with ODBC referential integrity errors. Those are good errors, in the sense that they prevent a bad delete, but they are a horrible message for the user experience.
I'm just looking for any great methods people use to handle this, across an application. I have most all of the not in list code handled to either let them add values, tell the user it is a fixed list, or tell them the list comes from another system and that they must address that list with the owners of that system.
Deleting is the big one I'm working through now, and I would love some thoughts from those who have mastered how to best handle it.
Thanks!
misscrf
It is never too late to become what you could have been ~ George Eliot