473,763 Members | 8,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem filtering recordset by values held in array

Hi

I am trying to filter a table of users to select only those records
whose roleID matches a value in an array. There could be any number of
IDs held in the array from one to a few hundred. The array is
generated by splitting a comma delimited memo field from a second
table in an Access DB. I can split the memo field OK, I can
response.write its values, but what I now want to do is add a value
from another table to my reponse write loop.

ie. memo field might contain IDs 1, 2, 4

This splits into array
1
2
4

And I want to match up with contents in the non-autonumber field of a
table wchich might look something like:
tblRoles
RoleID(autonumb er field), emailaddress
1, a@address.com
2, b@address.com
3, c@address.com
4, d@address.com

Such that what appears on my output page is:
a@address.com
b@address.com
d@address.com

i.e. no c because 3 is not in the array.
Full code of page so far:

<%@LANGUAGE="VB SCRIPT" CODEPAGE="1252" %>
<!--#include file="../Connections/connMomentaDB.a sp" -->
<%
Dim rsLastList__MMC olParam
rsLastList__MMC olParam = "1"
If (Session("LastL ist") <> "") Then
rsLastList__MMC olParam = Session("LastLi st")
End If
%>
<%
Dim rsLastList
Dim rsLastList_numR ows

Set rsLastList = Server.CreateOb ject("ADODB.Rec ordset")
rsLastList.Acti veConnection = MM_connMomentaD B_STRING
rsLastList.Sour ce = "SELECT ListID, MailingList FROM tblxCampPers
WHERE ListID = " + Replace(rsLastL ist__MMColParam , "'", "''") + ""
rsLastList.Curs orType = 0
rsLastList.Curs orLocation = 2
rsLastList.Lock Type = 1
rsLastList.Open ()

rsLastList_numR ows = 0
%>
<% varMailingList = split(rsLastLis t("MailingList" ), ", ", -1, 1 ) %>
<%
Dim rsRoles
Dim rsRoles_numRows

Set rsRoles = Server.CreateOb ject("ADODB.Rec ordset")
rsRoles.ActiveC onnection = MM_connMomentaD B_STRING
rsRoles.Source = "SELECT RoleID, emailadd FROM tblRoles"
rsRoles.CursorT ype = 0
rsRoles.CursorL ocation = 2
rsRoles.LockTyp e = 1
rsRoles.Open()

rsRoles_numRows = 0
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitl ed Document</title>
</head>

<body>
<p>Your mailing list has been created and is list number
<%=(rsLastList. Fields.Item("Li stID").Value)%>
</p>
<p>
' The section below currently writes the roleID, but I want it to
write the email address instead
<% for myCounter=0 to ubound(varMaili ngList)
response.write varMailingList( myCounter) & "<BR>" & vbcrlf
next
%>

</p>
<p>&nbsp;</p>
</body>
</html>
<%
rsLastList.Clos e()
Set rsLastList = Nothing
%>
<%
rsRoles.Close()
Set rsRoles = Nothing
%>

I presume I need a second loop within the varMailingList loop which
returns the matching record in rsRoles?

Any help gratefully received!

Thanks in advance

TimP
Jul 22 '05 #1
8 2106
If you have a string that starts out as 1, 2, 4, instead of splitting it
into an array, keep it as is and use it in your WHERE clause.

Example:

strNumbers = "1, 2, 4"
sSQL = "SELECT RoleID, emailadd FROM tblRoles WHERE RoleID IN (" &
strNumbers & ")"
'which would result in a query as:
'SELECT RoleID, emailadd FROM tblRoles WHERE RoleID IN (1, 2, 4)

Ray at work
"Tim Pollard" <ti************ *@btinternet.co m> wrote in message
news:f3******** *************** ***@posting.goo gle.com...
Hi

I am trying to filter a table of users to select only those records
whose roleID matches a value in an array. There could be any number of
IDs held in the array from one to a few hundred. The array is
generated by splitting a comma delimited memo field from a second
table in an Access DB. I can split the memo field OK, I can
response.write its values, but what I now want to do is add a value
from another table to my reponse write loop.

ie. memo field might contain IDs 1, 2, 4

This splits into array
1
2
4

And I want to match up with contents in the non-autonumber field of a
table wchich might look something like:
tblRoles
RoleID(autonumb er field), emailaddress
1, a@address.com
2, b@address.com
3, c@address.com
4, d@address.com

Such that what appears on my output page is:
a@address.com
b@address.com
d@address.com

Jul 22 '05 #2
Hi Ray

Thanks for the reply and your suggestion.

What you say makes sense, but when I tried it I got a data type
mismatch error - because the RoleID field is a number (access
autonumber) whilst the string of numbers is text, having been held in
a memo field.

Do you know if it is possible to turn the text field back in to a
string of numbers when you define it as a string?

Many thanks for taking the trouble to reply.

Regards

Tim
Jul 22 '05 #3
Tim Pollard wrote:
Hi Ray

Thanks for the reply and your suggestion.

What you say makes sense, but when I tried it I got a data type
mismatch error - because the RoleID field is a number (access
autonumber) whilst the string of numbers is text, having been held in
a memo field.


Show us what you did. Ray's suggestion should have worked, so it appears as
if you did something different. Verify that your sql statement is correct by
response.writin g it.

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #4
CAn you Response.Write your final SQL query before populating the recordset
and then post if back here?

Eg.

sSQL = "SELECT RoleID, emailadd FROM tblRoles WHERE RoleID IN (" &
strNumbers & ")"
RESPONSE.WRITE SSQL
RESPONSE.END

Ray at work

"Tim Pollard" <ti************ *@btinternet.co m> wrote in message
news:f3******** *************** ***@posting.goo gle.com...
Hi Ray

Thanks for the reply and your suggestion.

What you say makes sense, but when I tried it I got a data type
mismatch error - because the RoleID field is a number (access
autonumber) whilst the string of numbers is text, having been held in
a memo field.

Do you know if it is possible to turn the text field back in to a
string of numbers when you define it as a string?

Many thanks for taking the trouble to reply.

Regards

Tim

Jul 22 '05 #5
Hi Ray & Co

Thanks for your responses.

I'm normally a DWMX04 user so I'm not used to hand coding my sql,
which is probably why I'm having a spot of bother.

If I do exactly what Ray says all is OK.

Code:

<%@LANGUAGE="VB SCRIPT" CODEPAGE="1252" %>
<!--#include file="../Connections/connMomentaDB.a sp" -->
<%
Dim rsLastList__MMC olParam
rsLastList__MMC olParam = "1"
If (Session("LastL ist") <> "") Then
rsLastList__MMC olParam = Session("LastLi st")
End If
%>
<%
Dim rsLastList
Dim rsLastList_numR ows

Set rsLastList = Server.CreateOb ject("ADODB.Rec ordset")
rsLastList.Acti veConnection = MM_connMomentaD B_STRING
rsLastList.Sour ce = "SELECT ListID, MailingList FROM tblxCampPers
WHERE ListID = " + Replace(rsLastL ist__MMColParam , "'", "''") + ""
rsLastList.Curs orType = 0
rsLastList.Curs orLocation = 2
rsLastList.Lock Type = 1
rsLastList.Open ()

rsLastList_numR ows = 0
%>
<% strNumbers = (rsLastList.Fie lds.Item("Maili ngList").Value)
sSQL = "SELECT RoleID, emailadd FROM tblRoles WHERE RoleID IN (" &
strNumbers & ")"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitl ed Document</title>
</head>

<body>
<p>Your mailing list has been created and is list number
<%=(rsLastList. Fields.Item("Li stID").Value)%>
</p>
<p>
</p>
<p><%
Response.Write sSQL & "<BR>" & vbcrlf
%>
</p>
<p>&nbsp;</p>
</body>
</html>
<%
rsLastList.Clos e()
Set rsLastList = Nothing
%>

This produces a page like this:

Your mailing list has been created and is list number 15

SELECT RoleID, emailadd FROM tblRoles WHERE RoleID IN (428, 198, 796,
1251, 51, 707, 964, 496)

So far so good! The problem comes when I try to define a DW recordset
based on the same sql. If I do this I get no error now but when I try
to create a repeat region of my email addresses it is blank.

Presumably I need to do this latter step by hand also.

All I want is a simple list of email addresses e.g.

a@bc.com,
b@de.com,
c@gh.com
etc.

Sorry if I'm being dim!

Thanks again for the input.

Regards

Tim
Jul 22 '05 #6

"Tim Pollard" <ti************ *@btinternet.co m> wrote in message
news:f3******** *************** ***@posting.goo gle.com...
If I do exactly what Ray says all is OK.


That holds true in every facet of life. :P

Ray at work
Jul 22 '05 #7
Hi Ray

I've been back and done what you said again, carefully this time, and
lo and behold it works perfectly.

Thank you very much for taking the time to help me.

Regards

TP
Jul 22 '05 #8
You're quite welcome. :]

Ray at work

"Tim Pollard" <ti************ *@btinternet.co m> wrote in message
news:f3******** *************** ***@posting.goo gle.com...
Hi Ray

I've been back and done what you said again, carefully this time, and
lo and behold it works perfectly.

Thank you very much for taking the time to help me.

Regards

TP

Jul 22 '05 #9

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

Similar topics

6
3309
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site class, Assembly class, and Material class as follows... Site Class (clsSite): Option Explicit
23
3252
by: Rob Meade | last post by:
Lo all, Ok - this is what I was aiming to do, and then I thought - naahhh, that cant be right! query database results to recordset results to array using GetRows update values in one column in array <BOING>
11
6639
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to transfer data across.On the serve I am using Socket 2 API (recv function to read bytes)and not using ..NET. I use FileStream to open the file on the pocket pc, then associate a BinaryReader object with the stream and call ReadBytes to read all the...
8
3899
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter = "'Record ID' = '0'"; theView.RowStateFilter = DataViewRowState.ModifiedCurrent; Debug.WriteLine(string.Format("RowFilter = {0}", theView.RowFilter)); RecordDataGrid.DataSource = theView; RecordDataGrid.DataBind();
2
14748
by: Zlatko Matiæ | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
0
3131
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset ' Append one or more fields... Call rs.Fields.Append("Number", adInteger)
0
2003
by: Lyn | last post by:
I have a problem using the form .Filter and .FilterOn properties which causes Access to crash (as detailed in a separate post). The form operates in continuous mode, displaying matching records from a file based on a search criterion. This basic functionality works just fine. I decided to allow the user to narrow down the output by providing some extra controls to allow the user to filter the recordset via the .Filter form property. ...
4
2556
by: Gilberto | last post by:
Hello, I have a couple of forms using the code to FIND AS YOU TYPE from Allen Browne (http://allenbrowne.com/AppFindAsUType.html). It worked PERFECTLY until yesterday when i splitted the db into FE/BE. The tables link ok and everything works ok EXCEPT this function. When i open the form it gives me a underlining line (iReturn = ctl.Parent.PageIndex IN THE PARENTNUMBER function in BOLD) and indicating that iReturn=0. I am new with access and...
43
2387
by: John | last post by:
Hi This .net is driving me crazy!! In VB6 I had a type which contained a couple of multi-dimentional arrays which i used to create and read records: Type AAA : Array1(10,10,2) as Integer
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.