query results into string?

  • Thread starter Thread starter Jerome
  • Start date Start date
J

Jerome

Hi,

Is it possible to create a query that copies its results into a
textfield on a form?

Let's say I define a query that selects a certain field on all records.
So I'll get a 1 column list of i.e. 50 items.
But I don't want those 50 items in a column, I want them in a text field
like this: "[item1];[item2];[item3];etc ..."

How do I create this loop?

I guess you have to manually program the query and its execution?
So you can write something like: txtString=txtString & [item(i)] & ";"

Any help is greatly appreciated.

Jerome
 
Open the query as an ADO recordset and use the GetString method (detailed in
Help) to return the results as a string.

You can set the row delimeter as ";" so you get a string you can use in the
TO of your email.

Make sure you have a reference to ADO set, and ensure that if you are mixing
ADO and DAO that you use clear definitions, e.g.

Dim rs as ADODB.Recordset

Not:

Dim rs as Recordset

Hope that helps

Paul
www.pdtech.co.uk
 
Paul,

I have Access 2000 and cannot find the GetString method in help. Neither can
I find it on the Microsoft website.

Can you point me at another location to find the help?

Thanks,

Michael.


Paul said:
Open the query as an ADO recordset and use the GetString method (detailed
in Help) to return the results as a string.

You can set the row delimeter as ";" so you get a string you can use in
the TO of your email.

Make sure you have a reference to ADO set, and ensure that if you are
mixing ADO and DAO that you use clear definitions, e.g.

Dim rs as ADODB.Recordset

Not:

Dim rs as Recordset

Hope that helps

Paul
www.pdtech.co.uk


Jerome said:
Hi,

Is it possible to create a query that copies its results into a textfield
on a form?

Let's say I define a query that selects a certain field on all records.
So I'll get a 1 column list of i.e. 50 items.
But I don't want those 50 items in a column, I want them in a text field
like this: "[item1];[item2];[item3];etc ..."

How do I create this loop?

I guess you have to manually program the query and its execution?
So you can write something like: txtString=txtString & [item(i)] & ";"

Any help is greatly appreciated.

Jerome
 
Hi,


That is for an ADO recordset. With DAO recordset, try the string function
Join() over a GetRows()


Hoping it may help,
Vanderghast, Access MVP

--------------From the help file--------------
GetString Method
Returns the Recordset as a string.

Syntax
Variant = recordset.GetString(StringFormat, NumRows, ColumnDelimiter,
RowDelimiter, NullExpr)Return Value
Returns the Recordset as a string-valued Variant (BSTR).

Parameters
StringFormat
A StringFormatEnum value that specifies how the Recordset should be
converted to a string. The RowDelimiter, ColumnDelimiter, and NullExpr
parameters are used only with a StringFormat of adClipString.
NumRows
Optional. The number of rows to be converted in the Recordset. If NumRows
is not specified, or if it is greater than the total number of rows in the
Recordset, then all the rows in the Recordset are converted.
ColumnDelimiter
Optional. A delimiter used between columns, if specified, otherwise the
TAB character.
RowDelimiter
Optional. A delimiter used between rows, if specified, otherwise the
CARRIAGE RETURN character.
NullExpr
Optional. An expression used in place of a null value, if specified,
otherwise the empty string.
Remarks
Row data, but no schema data, is saved to the string. Therefore, a Recordset
cannot be reopened using this string.

This method is equivalent to the RDO GetClipString method.

See Also
Visual Basic Example

Applies To: Recordset Object

-----------------------------------

Michael said:
Paul,

I have Access 2000 and cannot find the GetString method in help. Neither
can I find it on the Microsoft website.

Can you point me at another location to find the help?

Thanks,

Michael.


Paul said:
Open the query as an ADO recordset and use the GetString method (detailed
in Help) to return the results as a string.

You can set the row delimeter as ";" so you get a string you can use in
the TO of your email.

Make sure you have a reference to ADO set, and ensure that if you are
mixing ADO and DAO that you use clear definitions, e.g.

Dim rs as ADODB.Recordset

Not:

Dim rs as Recordset

Hope that helps

Paul
www.pdtech.co.uk


Jerome said:
Hi,

Is it possible to create a query that copies its results into a
textfield on a form?

Let's say I define a query that selects a certain field on all records.
So I'll get a 1 column list of i.e. 50 items.
But I don't want those 50 items in a column, I want them in a text field
like this: "[item1];[item2];[item3];etc ..."

How do I create this loop?

I guess you have to manually program the query and its execution?
So you can write something like: txtString=txtString & [item(i)] & ";"

Any help is greatly appreciated.

Jerome
 
Back
Top