473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Recordset FindFirst Not Working, Why?

Hello:

I am an ambitious novice...I have a main form "frmGeneralContracting"
that has a subform on it called "frmsubDeliverables" and I am trying
to restrict editing if the current user's login name is in another
subform "frmUserNameRightsProject2Names" that is also attached to the
main form. I want to allow edits, deletes, and additions on the
frmsubDeliverables form to the record and if not they only can view
that record.

I call my GetUserNameRowSecurity function on the OnCurrent event of
the subform frmsubDeliverables.

I have looked at this all day and I can't figure out why my recordset
findfirst isn't working. It seems to totally disregard my code...if I
set the subform properties on the form to false for all 3 allows I
can't edit any records even if my username is in the
tblUserNameRightsProject2Names and if I set the subform properties to
true I can edit all the records regardless if my name is is in
tblUserNameRightsProject2Names for that particular record.

My module code is below. Any help is greatly appreciated. PLEASE
help me.

- Wilma

***********************************

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

Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT
tblUserNameRightsProject2Names.fldUserNameProjectE dit FROM
GeneralContracting INNER JOIN tblUserNameRightsProject2Names ON
GeneralContracting.ID = tblUserNameRightsProject2Names.ID",
dbOpenSnapshot)
rst.FindFirst ("[tblUserNameRightsProject2Names].
[fldUserNameProjectEdit]" = "'" & stUser & "'")
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
End If

'************** Code End **************

Exit_Here:
rst.Close
Set rst = Nothing
Set DB = Nothing
Exit Function

RowError_Handler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Here
End Function

Mar 12 '07 #1
3 7400
I believe that this...

rst.FindFirst ("[tblUserNameRightsProject2Names].
[fldUserNameProjectEdit]" = "'" & stUser & "'")

Should likely look like this...

rst.FindFirst ("[tblUserNameRightsProject2Names].
[fldUserNameProjectEdit] = '" & stUser & "'")

Your useage of double and single quotes does not build a valid
statement.

Mar 12 '07 #2
On Mar 12, 6:02 pm, "storrboy" <storr...@sympatico.cawrote:
I believe that this...

rst.FindFirst("[tblUserNameRightsProject2Names].
[fldUserNameProjectEdit]" = "'" & stUser & "'")

Should likely look like this...

rst.FindFirst("[tblUserNameRightsProject2Names].
[fldUserNameProjectEdit] = '" & stUser & "'")

Your useage of double and single quotes does not build a valid
statement.
Thanks storrboy my quotes were messing it up but now I have another
problem that I think is related to findfirst and the recordset query.
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

'************************************************* *****************
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.For m

Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT
tblUserNameRightsProject2Names.fldUserNameProjectE dit,
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

Mar 13 '07 #3
Try this. I've added and removed (I hope not too much) as somethings
were redundant, some were not used and some were hard to follow.
Compile the module before running to catch syntax or spelling errors.
If it seems to work at first, try it a few more times to make sure.

'************************************************* *****************
Function GetUserNameRowSecurity()
On Error GoTo RowError_Handler

Dim myForm As Form '------------CHANGED TO FORM
'Dim donothing As String '---NOT USED, COMMENTED OUT
Dim stUser As String
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Dim sqlStr As String '-----------------ADDED BY STORRBOY
Dim bvAllowRights As Boolean '--ADDED BY STORRBOY

stUser = Environ("UserName")
Set myForm = Forms!frmGeneralContracting.frmsubDeliverables.For m

'THIS MAKES THE SQL A BIT SMALLER AND EASIER TO READ
'INSTEAD OF USING FIND METHODS, USE CRITERIA IN QUERY
'THE FINDFIRST USAGE SHOULD NOW BE TAKEN CARE OF BY THE
'CRITERIA AND THE INNER JOIN BEING EQUAL ALREADY

sqlStr = "SELECT tUNRP2.fldUserNameProjectEdit, tUNRP2.ID AS
NameID,"
sqlStr = sqlStr & " GC.ID AS ContrID FROM GeneralContracting GC"
sqlStr = sqlStr & " INNER JOIN tblUserNameRightsProject2Names
tUNRP2"
sqlStr = sqlStr & " ON GC.ID = tUNRP2.ID WHERE("
sqlStr = sqlStr & " tUNRP2.fldUserNameProjectEdit = '" & stUser &
"');"

Set DB = CurrentDb
Set rst = DB.OpenRecordset(sqlStr, dbOpenSnapshot)
If rst.RecordCount 0 Then bvAllowRights = True

With myForm
.AllowAdditions = bvAllowRights
.AllowDeletions = bvAllowRights
.AllowEdits = bvAllowRights
End With

Exit_Here:
On Error Resume Next
rst.Close
Set rst = Nothing ' Release the object
Set DB = Nothing ' Release the object
Set myForm = Nothing ' Release the object
Exit Function

RowError_Handler:
MsgBox Err.Number & ": " & Err.Description
Exit Function
End Function
Mar 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Peter Bailey | last post by:
I have a querystring built up in vba and I want to open a recordset based on the sql and pass the date value to a textbox or label for use elsewhere on the form. The recordset isnt working as it...
5
by: Paul | last post by:
The 2 statements below work perfectly when using them individually. But when I try to concatenate them, they don't. rst.FindFirst " = " & OldQuoteNumber rst.FindFirst " Is Null" Can someone...
2
by: Bruce | last post by:
I have two databases on the same machine, both using office xp. One database has the recordset FindFirst and NoMatch methods available to it, the other doesn't. What's going on? Cheers, ...
24
by: Salad | last post by:
Every now and then I see ads that state something like "Experience with Large Databases ...multi-gig...blah-de-blah" And I have to laugh. What's the difference between a large or small database? ...
2
by: Tom Clavel | last post by:
Scratching my head. I am using the filter property on a combo box .AfterUpdate event to get to a single client record. This is causing a some strange behavior: As I enter a subform, I get a no...
2
by: JasCot75 | last post by:
Hello all, my first go at this so please be gentle. I'm putting together a simple access database and have run into a problem with date function I found on the web. The code appears to work, but...
5
Scott Price
by: Scott Price | last post by:
I'm not quite ready to give up on this yet... Using MS Access 2003, WinXP SP2. I have a listbox that I'm trying to get to highlight (select) a specific record using the GotFocus event (the...
2
by: nash2love | last post by:
Hi I am new to V.B . currently i am using MS-Access as backend and V.B 6.0 as front end. now i am creating one table in MS-Access with fields SName and SAge and i entered 15 records with out any...
13
by: ChrisD76 | last post by:
Hi, I am new to using VBA, and have been working with DAO Recordsets. I'm working on a little problem, and think that DAO Recordsets are the solution. I've been playing around with them to try and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.