Take a field from Query output

thomas49th

New member
Local time
Today, 05:57
Joined
Mar 11, 2007
Messages
8
Hi, an output from a query gives me so many records with the fields "Name" and "Type". How do i take all the records in my query with the field "Name" and put them into a string, parsed with a space(space inbetween each one record "Name")?

Thx
 
You need to "loop".

PHP:
Dim db As Object
Dim rst As Object
Dim strSQL As String

strSQL = "SELECT * FROM yourQueryName;"

Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)

rst.MoveFirst

With rst
    Do Until .EOF = True
        myTempVar = [Fieldname]
        myLongVar = myLongVar & ";" & myTempVar
    .MoveNext
    Loop
End With

    rst.Close
    db.Close

I think something like that should work. Use "MsgBox [Fieldname]" to check that the loop code works, and go from there.

You probably need a if for if myLongVar = Null, for the first record. (If Isnull(myLongVar)).
 
I get an compile error "External name not defined" and highlights

myTempVar = [Item Name]

I tried putting

myTempVar = "[Item Name]"

but then my output is just a string of "[Item Name];[Item Name]"... and so on.

What should I do?

Thx

EDIT: Looking at the code I find nothing is actually done with myTempVar except it's put into a string. It's not used as SQL by a recordset... is it?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom