can anybody help me.
I'm trying to read from a table of users to find out who has read only access to a form. I have some code but i think that it is wrong somewhere.
First is a module with:-
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Next is the code on the on open part of the form:-
Private Sub Form_Open(Cancel As Integer)
Dim User1 As String ' variable to hold name
Dim rst As Recordset 'variable to hold User names
Dim i As Long 'variable to hold rst record loop
Dim chkAllowed As Boolean 'variable to hold whether read only or not (read only = -1, Allowed = 0)
User1 = Space(255) 'create a
GetUserName User1, 255
Set rst = CurrentDb.OpenRecordset("Users", dbOpenDynaset)
chkAllowed = 0 'allocate variable to allowed initially
If rst.RecordCount > 0 Then
'populate Recordset
rst.MoveLast
rst.MoveFirst
For i = 1 To rst.RecordCount
If rst!Uname = User1 Then ' there is a match therefore set to read only
chkAllowed = -1
Exit For 'exit loop if match found ie. Read only
End If
rst.MoveNext
Next i
End If
If chkAllowed = -1 Then
Me.AllowAdditions = -1
Me.AllowDeletions = -1
Me.AllowEdits = -1
Me.DelDateSubform.Form.AllowAdditions = -1
Me.DelDateSubform.Form.AllowDeletions = -1
Me.DelDateSubform.Form.AllowEdits = -1
Me.VisChangeSubform.Form.AllowAdditions = -1
Me.VisChangeSubform.Form.AllowDeletions = -1
Me.VisChangeSubform.Form.AllowEdits = -1
Me.[Delivery SubForm].Form.AllowAdditions = -1
Me.[Delivery SubForm].Form.AllowDeletions = -1
Me.[Delivery SubForm].Form.AllowEdits = -1
Else
Me.AllowAdditions = 0
Me.AllowDeletions = 0
Me.AllowEdits = 0
Me.DelDateSubform.Form.AllowAdditions = 0
Me.DelDateSubform.Form.AllowDeletions = 0
Me.DelDateSubform.Form.AllowEdits = 0
Me.VisChangeSubform.Form.AllowAdditions = 0
Me.VisChangeSubform.Form.AllowDeletions = 0
Me.VisChangeSubform.Form.AllowEdits = 0
Me.[Delivery SubForm].Form.AllowAdditions = 0
Me.[Delivery SubForm].Form.AllowDeletions = 0
Me.[Delivery SubForm].Form.AllowEdits = 0
End If
Exit Sub
End Sub
I'm trying to read from a table of users to find out who has read only access to a form. I have some code but i think that it is wrong somewhere.
First is a module with:-
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Next is the code on the on open part of the form:-
Private Sub Form_Open(Cancel As Integer)
Dim User1 As String ' variable to hold name
Dim rst As Recordset 'variable to hold User names
Dim i As Long 'variable to hold rst record loop
Dim chkAllowed As Boolean 'variable to hold whether read only or not (read only = -1, Allowed = 0)
User1 = Space(255) 'create a
GetUserName User1, 255
Set rst = CurrentDb.OpenRecordset("Users", dbOpenDynaset)
chkAllowed = 0 'allocate variable to allowed initially
If rst.RecordCount > 0 Then
'populate Recordset
rst.MoveLast
rst.MoveFirst
For i = 1 To rst.RecordCount
If rst!Uname = User1 Then ' there is a match therefore set to read only
chkAllowed = -1
Exit For 'exit loop if match found ie. Read only
End If
rst.MoveNext
Next i
End If
If chkAllowed = -1 Then
Me.AllowAdditions = -1
Me.AllowDeletions = -1
Me.AllowEdits = -1
Me.DelDateSubform.Form.AllowAdditions = -1
Me.DelDateSubform.Form.AllowDeletions = -1
Me.DelDateSubform.Form.AllowEdits = -1
Me.VisChangeSubform.Form.AllowAdditions = -1
Me.VisChangeSubform.Form.AllowDeletions = -1
Me.VisChangeSubform.Form.AllowEdits = -1
Me.[Delivery SubForm].Form.AllowAdditions = -1
Me.[Delivery SubForm].Form.AllowDeletions = -1
Me.[Delivery SubForm].Form.AllowEdits = -1
Else
Me.AllowAdditions = 0
Me.AllowDeletions = 0
Me.AllowEdits = 0
Me.DelDateSubform.Form.AllowAdditions = 0
Me.DelDateSubform.Form.AllowDeletions = 0
Me.DelDateSubform.Form.AllowEdits = 0
Me.VisChangeSubform.Form.AllowAdditions = 0
Me.VisChangeSubform.Form.AllowDeletions = 0
Me.VisChangeSubform.Form.AllowEdits = 0
Me.[Delivery SubForm].Form.AllowAdditions = 0
Me.[Delivery SubForm].Form.AllowDeletions = 0
Me.[Delivery SubForm].Form.AllowEdits = 0
End If
Exit Sub
End Sub