FindFirst Criteria Problem

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
 
G

Guest

If when you say "subtables" you are talking about the ID of the MAIN form
matching the Master/Child ID of the SubForm ... then you could control what
records showed up in the subform with the Master/Child, and wouldn't have to
worry that the ID's didn't match.

As for permissions, I would bypass all the code of handling the username,
and instead create a security system using the Wizard with individual and
group permissions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top