How do I select records to be opened in a form with an array?

  • Thread starter Thread starter Niklas Östergren
  • Start date Start date
N

Niklas Östergren

Hi!

I want to open a form showing only the records that I have stored in an
array.

Right now I open the form showing only ONE record, like this:

DoCmd.OpenForm "frmNewMemberRegistration", acNormal, , "MemberID = " &
glngNewMemberID, , acWindowNormal

But I´d like to open this form and showing record where:
"MemberID = " & glngNewMemberID AND glngarrFamilyMemberID()

Where glngarrFamilyMemberID() is an array holding primary key for newly
added records in the recordsource for frmNewMemberRegistration.

How do I do this the best way?

TIA!
// Niklas
 
Use Split() to parse the array into a string, with a comma separating the
items so you can use it with the IN operator.

The target string will end up something like this:
"MemberID IN (5,7,99)"
or if the MemberID is actually a Text field:
"MemberID IN (""a"",""g"",""y"")"
 
Thank´s Allen!

I´m not so familiare with Split() function so I might be out of line here.
The array (glngarrFamilyMemberID) is a global array holding long variables.
Should the split be used this way?:

strWhere = Split(glngarrFamilyMemberID(), ",")

I´m going to use variable strWhere later on to open the form like this:

DoCmd.OpenForm "frmNewMemberRegistration", acNormal, , "MemberID = " &
strWhere, , acWindowNormal


TIA!
// Niklas
 
I don´t unsderstand how you ment me to use Split() so I did it like this
instead:

intIdx = 0
For intIdx = 0 To UBound(glngarrFamilyMemberID) - 1
strWhere = strWhere & " OR MemberID = " &
CStr(glngarrFamilyMemberID(intIdx))
Next intIdx

It works but may not be the best way of doing it.

/ Niklas
 
No. There's more to it than that.

You have to create a string, with commas between the values, put the results
in brackets, and then add the field name and IN operator to the front.
 
Back
Top