W
wvhines
I'm an ambitious novice. My problem (I think) is related to
findfirst
and the recordset query...the findfirst criteria.
I want the code to allow the user to edit, add, delete only if the ID
field in the subtables match AND the login names match. Instead it
is
allowing editing, adding, and deleting for ALL project IDs just as
long as the users login name is somewher in the subtable
"tblUserNameRightsProject2Names".
Can you figure out why? How can I fix it? I'm stumped...my
revised code is below. Thanks in advance
More info...I have a main form "frmGeneralContracting"
that has a subform on it called "frmsubDeliverables".
I call my GetUserNameRowSecurity function on the OnCurrent
event of the subform frmsubDeliverables.
'******************************************************************
Function GetUserNameRowSecurity()
On Error GoTo RowError_Handler
'************** Code Start **************
Dim myForm As Object
Dim donothing As String
Dim stUser As String
Dim rst As DAO.Recordset
Dim DB As DAO.Database
stUser = Environ("UserName")
Set myForm = Forms!frmGeneralContracting.frmsubDeliverables.Form
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT
tblUserNameRightsProject2Names.fldUserNameProjectEdit,
GeneralContracting.ID, tblUserNameRightsProject2Names.ID FROM
GeneralContracting INNER JOIN tblUserNameRightsProject2Names ON
GeneralContracting.ID = tblUserNameRightsProject2Names.ID",
dbOpenSnapshot)
rst.FindFirst "( [tblUserNameRightsProject2Names]!
[fldUserNameProjectEdit] = '" & stUser & "' ) AND
( [GeneralContracting]![ID] = [tblUserNameRightsProject2Names]!
[ID] )"
If rst.NoMatch Then
With myForm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With
Else
With myForm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With
Set myForm = Nothing ' Release the object
End If
'************** Code End **************
Exit_Here:
rst.Close
Set rst = Nothing ' Release the object
Set DB = Nothing ' Release the object
Exit Function
RowError_Handler:
MsgBox Err.Number & ": " & Err.Description
Exit Function
End Function
findfirst
and the recordset query...the findfirst criteria.
I want the code to allow the user to edit, add, delete only if the ID
field in the subtables match AND the login names match. Instead it
is
allowing editing, adding, and deleting for ALL project IDs just as
long as the users login name is somewher in the subtable
"tblUserNameRightsProject2Names".
Can you figure out why? How can I fix it? I'm stumped...my
revised code is below. Thanks in advance
More info...I have a main form "frmGeneralContracting"
that has a subform on it called "frmsubDeliverables".
I call my GetUserNameRowSecurity function on the OnCurrent
event of the subform frmsubDeliverables.
'******************************************************************
Function GetUserNameRowSecurity()
On Error GoTo RowError_Handler
'************** Code Start **************
Dim myForm As Object
Dim donothing As String
Dim stUser As String
Dim rst As DAO.Recordset
Dim DB As DAO.Database
stUser = Environ("UserName")
Set myForm = Forms!frmGeneralContracting.frmsubDeliverables.Form
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT
tblUserNameRightsProject2Names.fldUserNameProjectEdit,
GeneralContracting.ID, tblUserNameRightsProject2Names.ID FROM
GeneralContracting INNER JOIN tblUserNameRightsProject2Names ON
GeneralContracting.ID = tblUserNameRightsProject2Names.ID",
dbOpenSnapshot)
rst.FindFirst "( [tblUserNameRightsProject2Names]!
[fldUserNameProjectEdit] = '" & stUser & "' ) AND
( [GeneralContracting]![ID] = [tblUserNameRightsProject2Names]!
[ID] )"
If rst.NoMatch Then
With myForm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With
Else
With myForm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With
Set myForm = Nothing ' Release the object
End If
'************** Code End **************
Exit_Here:
rst.Close
Set rst = Nothing ' Release the object
Set DB = Nothing ' Release the object
Exit Function
RowError_Handler:
MsgBox Err.Number & ": " & Err.Description
Exit Function
End Function