Build a string with a tables emelemts (via recordset)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I have the following code that builds a string with an array (myArr). I
have these values in myFields of myTable. How can I adjust my code to refer
to myField instread of a static array? I think via a recordset, but not sure
how to do it.

Code

Function mySeclist()
myArr = Array("Blue", "Red","Yellow")

l = 1

For Each x In myArr
If l = 1 Then
y = x
Else
y = y & "+" & x
End If
l = l + 1
Next x
mySeclist = y
End Function


Regards,

Bruce
 
Since there are three colors, I will assume you have three records with the
MyField field;

Function CreateString() As String
Dim DB As DAO.Database
Dim Rst As DAO.Recordset
Set DB = CurrentDB()
Set Rst = DB.OpenRecordset("MyTable")
Do Until Rst.EOF
CreateString = CreateString & """Rst!MyField & """ & ","
Rst.MoveNext
Loop
CreateString = Left(CreateString,Len(CreateString)-1)
MsgBox CreateString
Rst.Close
Set Rst = Nothing
Set DB = Nothing
End Function

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
Steve said:
Since there are three colors, I will assume you have three records with the
MyField field;

Function CreateString() As String
Dim DB As DAO.Database
Dim Rst As DAO.Recordset
Set DB = CurrentDB()
Set Rst = DB.OpenRecordset("MyTable")
Do Until Rst.EOF
CreateString = CreateString & """Rst!MyField & """ & ","
Rst.MoveNext
Loop
CreateString = Left(CreateString,Len(CreateString)-1)
MsgBox CreateString
Rst.Close
Set Rst = Nothing
Set DB = Nothing
End Function

PC Datasheet

--
This is to inform 'newbees' here about PCD' Steve:
http://home.tiscali.nl/arracom/whoissteve.html
Until now 3650+ pageloads, 2350+ first-time visitors (these figures are rapidly increasing)

Why is this ???
Because Steve is the ONLY person here who continues to advertise in the groups.

It is not relevant whether he advertised in *this* particular post or not...
==> We want him to know that these groups are *not* his private hunting grounds!

For those who don't like too see all these messages:
==> Simply killfile 'StopThisAdvertising'.
Newbees will still see this warning-message.

ArnoR
 
Back
Top