Build a string with a tables emelemts (via recordset)

B

Bruce

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
 
S

Steve

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top