473,506 Members | 14,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a faster way

I am looking for the most efficient method to check for a entity
membership in a group. Is there a better method than this? I am
working with a native Access database. At some point I'll probably end
up splitting the data from the front end.

Public Function isGroupMember(lngEntityID As Long, lngGroupID As Long)
As Boolean
On Error GoTo err_isGroupMember
Dim rs As New ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT tblGroupMembership.GroupID,
tblGroupMembership.EntityID FROM tblGroupMembership WHERE
(((tblGroupMembership.GroupID)=" & lngGroupID & ") AND
((tblGroupMembership.EntityID)=" & lngEntityID & "));"
rs.Open strSQL, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly

If rs.EOF Then
isGroupMember = False
Else
isGroupMember = True
End If
rs.Close
Set rs = Nothing

err_isGroupMember:
If Err <> 0 Then
isGroupMember = False
End If
End Function

Jan 22 '06 #1
7 1612
How about:
Not IsNull(DLookup("GroupID", "tblGroupMembership", _
"(GroupID = " & lngGroupID & ") AND (EntityID = " & lngEntityID & ")"))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Access" <al*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am looking for the most efficient method to check for a entity
membership in a group. Is there a better method than this? I am
working with a native Access database. At some point I'll probably end
up splitting the data from the front end.

Public Function isGroupMember(lngEntityID As Long, lngGroupID As Long)
As Boolean
On Error GoTo err_isGroupMember
Dim rs As New ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT tblGroupMembership.GroupID,
tblGroupMembership.EntityID FROM tblGroupMembership WHERE
(((tblGroupMembership.GroupID)=" & lngGroupID & ") AND
((tblGroupMembership.EntityID)=" & lngEntityID & "));"
rs.Open strSQL, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly

If rs.EOF Then
isGroupMember = False
Else
isGroupMember = True
End If
rs.Close
Set rs = Nothing

err_isGroupMember:
If Err <> 0 Then
isGroupMember = False
End If
End Function

Jan 22 '06 #2
DCount(...as in Allen's example...) > 0
and
Nz(DLookup(...as in Allen's example...)) <> ""
work as well.

i usually use the DCount variety of this test, and do so quite often.

Allen,

you see any advantages, disadvantages to either approach?

Jan 22 '06 #3
Not CurrentProject.Connection.Execute("SELECT * FROM
[4060148Transactions] WHERE CreditAccountID = 19 AND DebitAccountID =
18").BOF

Jan 22 '06 #4
DCount() is slower: Access can't just return the first value; it has to
continue through the entire table to get the total count.

The Nz() is superfluous, because DLookup() is wrongly programmed by
Microsoft. It is incapable of distinguishing between a Null and a
zero-length string (ZLS), so if returns Null even if it should return a ZLS.
So, in this case, checking for a ZLS adds nothing.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jamey" <ca*********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
DCount(...as in Allen's example...) > 0
and
Nz(DLookup(...as in Allen's example...)) <> ""
work as well.

i usually use the DCount variety of this test, and do so quite often.

Allen,

you see any advantages, disadvantages to either approach?

Jan 23 '06 #5
Public Function isGroupMember( _
lngEntityID As Long, _
lngGroupID As Long _
) As Boolean
Dim rs As New ADODB.Recordset
Dim strSQL As String

On Error GoTo err_isGroupMember

strSQL = "SELECT Count(*) " _
& "FROM tblGroupMembership " _
& "WHERE tblGroupMembership.GroupID)=" & lngGroupID _
& " AND tblGroupMembership.EntityID)=" & lngEntityID

call rs.Open(strSQL, CurrentProject.Connection, _
adOpenForwardOnly, adLockReadOnly

isGroupMember = cbool(rs(0))
rs.Close
Set rs = Nothing
Exit Function
err_isGroupMember:
If Err <> 0 Then
isGroupMember = False
End If
End Function

--

Terry Kreft
"Access" <al*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am looking for the most efficient method to check for a entity
membership in a group. Is there a better method than this? I am
working with a native Access database. At some point I'll probably end
up splitting the data from the front end.

Public Function isGroupMember(lngEntityID As Long, lngGroupID As Long)
As Boolean
On Error GoTo err_isGroupMember
Dim rs As New ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT tblGroupMembership.GroupID,
tblGroupMembership.EntityID FROM tblGroupMembership WHERE
(((tblGroupMembership.GroupID)=" & lngGroupID & ") AND
((tblGroupMembership.EntityID)=" & lngEntityID & "));"
rs.Open strSQL, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly

If rs.EOF Then
isGroupMember = False
Else
isGroupMember = True
End If
rs.Close
Set rs = Nothing

err_isGroupMember:
If Err <> 0 Then
isGroupMember = False
End If
End Function

Jan 23 '06 #6

"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Not CurrentProject.Connection.Execute("SELECT * FROM
[4060148Transactions] WHERE CreditAccountID = 19 AND DebitAccountID =
18").BOF


Surprised. Would have expected ...("SELECT Null FROM ...

Would that work as well?
(david)
Jan 23 '06 #7
I think so.
I suppose with a large table one might want to use:
"SELECT TOP 1 0 FROM [4060148Transactions] WHERE ...
(That's not ten; it's the top 1 of the "zeroeth" field.)
I expect there are many ways of dealing with this. If the table had a
million records and the code were to be run a million times a day I'd
probably use an index. As it is, this is takes between 50% and 70% of
the time the DLoopUp thingme takes/

Jan 24 '06 #8

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

Similar topics

36
2593
by: Armin Rigo | last post by:
Hi! This is a rant against the optimization trend of the Python interpreter. Sorting a list of 100000 integers in random order takes: * 0.75 seconds in Python 2.1 * 0.51 seconds in Python...
23
4697
by: YinTat | last post by:
Hi, I learned C++ recently and I made a string class. A code example is this: class CString { public: inline CString(const char *rhs) { m_size = strlen(rhs);
98
14306
by: jrefactors | last post by:
I heard people saying prefix increment is faster than postfix incerement, but I don't know what's the difference. They both are i = i+1. i++ ++i Please advise. thanks!!
65
12509
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
1
2701
by: James dean | last post by:
I done a test and i really do not know the reason why a jagged array who has the same number of elements as a multidimensional array is faster here is my test. I assign a value and do a small...
9
5151
by: VenuGopal | last post by:
Hi, why n++ executes faster than n+1..... or does it realli execute faster? thanks Venugopal.B
11
2942
by: ctman770 | last post by:
Hi Everyone, Is it faster to save the precise location of an html dom node into a variable in js, or to use getElementById everytime you need to access the node? I want to make my application...
12
9347
by: karthikbalaguru | last post by:
Hi, How is 'Int' Faster than 'Char' ? I think , 'Char' is small and so it should be easily & efficiently . Can someone here provide some info regarding this. Thanks and Regards, Karthik...
23
2496
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80)...
41
2638
by: c | last post by:
Hi every one, Me and my Cousin were talking about C and C#, I love C and he loves C#..and were talking C is ...blah blah...C# is Blah Blah ...etc and then we decided to write a program that...
0
7105
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
7308
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,...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.