Wappervliegje
Registered User.
- Local time
- Today, 02:32
- Joined
- Nov 11, 2014
- Messages
- 23
Hi people,
I'm trying to make a modified function SetTableValidation (this original function is founded at internet). But I get always an error number 3422 (Cannot modify table structure. Another user has the table open.). Only there are no users in my database, only my. That's very strang. That's why I've made an another function CloseAllObjects to ensure that all objects are closed in my database. But no results. Please, can you maybe find a wrong in my function? The aim of this function is if there another person than me is logged in my database, then this person can't modified all tables. I'm trying to make a "special key" for me only. I'm working with ACCDB/ACCDE and Access 2010.
Greeting from Wappervliegje!
I'm trying to make a modified function SetTableValidation (this original function is founded at internet). But I get always an error number 3422 (Cannot modify table structure. Another user has the table open.). Only there are no users in my database, only my. That's very strang. That's why I've made an another function CloseAllObjects to ensure that all objects are closed in my database. But no results. Please, can you maybe find a wrong in my function? The aim of this function is if there another person than me is logged in my database, then this person can't modified all tables. I'm trying to make a "special key" for me only. I'm working with ACCDB/ACCDE and Access 2010.
Greeting from Wappervliegje!
Code:
Public Function SetTableValidation()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim DLookUpSID As String
Set db = CurrentDb
DLookUpSID = DLookup("Security_ID", "tbl_Security_Level", "[Security_ID]=" & _
Nz(DLookup("User_Security_ID", "tbl_User", "[User_Name]='" & Environ("USERNAME") & "'"), "5") & "")
If DLookUpSID = 1 Then '1 = Developer/Administrator has only an access to all tables
For Each tdf In db.TableDefs
With tdf
.ValidationRule = False
.ValidationText = "Attention!" _
& vbCrLf & "This table has been blocked against modifications!"
End With
Next
End If
End Function
Code:
Public Function CloseAllObjects()
Dim aob As AccessObject
With CurrentData
'All Tables
For Each aob In .AllTables
If aob.IsLoaded Then
DoCmd.Close acTable, aob.Name, acSaveYes
End If
Next aob
'All queries
For Each aob In .AllQueries
If aob.IsLoaded Then
DoCmd.Close acQuery, aob.Name, acSaveYes
End If
Next aob
End With
With CurrentProject
'All forms
For Each aob In .AllForms
If aob.IsLoaded Then
DoCmd.Close acForm, aob.Name, acSaveYes
End If
Next aob
'All reports
For Each aob In .AllReports
If aob.IsLoaded Then
DoCmd.Close acReport, aob.Name, acSaveYes
End If
Next aob
'All pages
For Each aob In .AllDataAccessPages
If aob.IsLoaded Then
DoCmd.Close acDataAccessPage, aob.Name, acSaveYes
End If
Next aob
'All macros
For Each aob In .AllMacros
If aob.IsLoaded Then
DoCmd.Close acMacro, aob.Name, acSaveYes
End If
Next aob
'All modules
For Each aob In .AllModules
If aob.IsLoaded Then
DoCmd.Close acModule, aob.Name, acSaveYes
End If
Next aob
End With
End Function