Create a "string"

G

Guest

I have a table with many package codes (as well as many other fields). Also
listed as part of the table are the detail codes for the packages. i.e., if
there is a package code of "WQF" and it has 5 detail codes, WQF appears five
times in one column and the detail codes appear once in another column, one
detail code each line. I need to go from vertical to horizontal. How can I
get all the detail codes for each package into one line (record). There are
MANY.

As always, your help is appreciated.

- Danu
 
G

Guest

Thanks, Doug. I think the second module is the more appropriate, but there is
no value, such as "Owner", to let the module know when to create the string.
The values in the Detail column are all different. There is, however, a
column in the table which lets the user know how many detail codes are in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu
 
G

Guest

I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)
 
D

Douglas J. Steele

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg, fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1
FROM Data;
 
G

Guest

Okay. I "rewrote" the code below, substituting my fields and table for the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed" some out.
Finally got to the code and the entire statement is too long. Tried to break
it up into three lines and now I am getting "end of statement" errors.
I don't want to keep pestering...is there anywhere I can go for these errors
which everyone must run into? (deep sigh)

Thanks.

Douglas J. Steele said:
Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg, fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)
 
D

Douglas J. Steele

I'm afraid I don't understand what sort of problems you're having. That code
works perfectly: I ran it to ensure that what I suggested would work. There
is one change that's required on newer versions of Access, though. Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference set to the
DAO library. With any code module open, select Tools | References from the
menu bar, scroll through the list of available references until you find the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Danu said:
Okay. I "rewrote" the code below, substituting my fields and table for the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed" some out.
Finally got to the code and the entire statement is too long. Tried to
break
it up into three lines and now I am getting "end of statement" errors.
I don't want to keep pestering...is there anywhere I can go for these
errors
which everyone must run into? (deep sigh)

Thanks.

Douglas J. Steele said:
Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg, fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more appropriate, but
there
is
no value, such as "Owner", to let the module know when to create the
string.
The values in the Detail column are all different. There is,
however, a
column in the table which lets the user know how many detail codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The Access Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many other
fields).
Also
listed as part of the table are the detail codes for the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail codes, WQF
appears
five
times in one column and the detail codes appear once in another
column,
one
detail code each line. I need to go from vertical to horizontal.
How
can I
get all the detail codes for each package into one line (record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
G

Guest

Okay. I reset the statements to include "DAO". I went into References and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax error.

I receive a syntax error. The error starts at loSQL and ends at AS, which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an end-of-statement error
at "Data".

I seem to be going in circles. Again, thank you for your help. (This is when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I had no idea
that the 3.6 Object Library was needed.

- Danu

Douglas J. Steele said:
I'm afraid I don't understand what sort of problems you're having. That code
works perfectly: I ran it to ensure that what I suggested would work. There
is one change that's required on newer versions of Access, though. Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference set to the
DAO library. With any code module open, select Tools | References from the
menu bar, scroll through the list of available references until you find the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Danu said:
Okay. I "rewrote" the code below, substituting my fields and table for the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed" some out.
Finally got to the code and the entire statement is too long. Tried to
break
it up into three lines and now I am getting "end of statement" errors.
I don't want to keep pestering...is there anywhere I can go for these
errors
which everyone must run into? (deep sigh)

Thanks.

Douglas J. Steele said:
Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg, fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more appropriate, but
there
is
no value, such as "Owner", to let the module know when to create the
string.
The values in the Detail column are all different. There is,
however, a
column in the table which lets the user know how many detail codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The Access Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many other
fields).
Also
listed as part of the table are the detail codes for the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail codes, WQF
appears
five
times in one column and the detail codes appear once in another
column,
one
detail code each line. I need to go from vertical to horizontal.
How
can I
get all the detail codes for each package into one line (record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
D

Douglas J. Steele

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Okay. I reset the statements to include "DAO". I went into References and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax error.

I receive a syntax error. The error starts at loSQL and ends at AS, which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help. (This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I had no
idea
that the 3.6 Object Library was needed.

- Danu

Douglas J. Steele said:
I'm afraid I don't understand what sort of problems you're having. That
code
works perfectly: I ran it to ensure that what I suggested would work.
There
is one change that's required on newer versions of Access, though. Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference set to
the
DAO library. With any code module open, select Tools | References from
the
menu bar, scroll through the list of available references until you find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Danu said:
Okay. I "rewrote" the code below, substituting my fields and table for
the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed" some
out.
Finally got to the code and the entire statement is too long. Tried to
break
it up into three lines and now I am getting "end of statement" errors.
I don't want to keep pestering...is there anywhere I can go for these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more appropriate,
but
there
is
no value, such as "Owner", to let the module know when to create
the
string.
The values in the Detail column are all different. There is,
however, a
column in the table which lets the user know how many detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The Access
Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many other
fields).
Also
listed as part of the table are the detail codes for the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail codes,
WQF
appears
five
times in one column and the detail codes appear once in
another
column,
one
detail code each line. I need to go from vertical to
horizontal.
How
can I
get all the detail codes for each package into one line
(record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
G

Guest

Okay.
Added the quotes. Compiled it and received the message that the function
could not be found. It is the ONLY function in the db so I took the table and
the module and the macro to run the module and moved it to a new db. Compiled
it there and received the message that there is the wrong number of
arguments. Went to the area where the function is declared and removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the function
declarations there are four declarations. In the SQL statement, there are
four arguments except for Expr1. Could that have something to do with it?

There are many Access users here but they use high level queries and no
coding so I am basically alone on this. Thank you for your help.

Douglas J. Steele said:
It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Okay. I reset the statements to include "DAO". I went into References and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax error.

I receive a syntax error. The error starts at loSQL and ends at AS, which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help. (This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I had no
idea
that the 3.6 Object Library was needed.

- Danu

Douglas J. Steele said:
I'm afraid I don't understand what sort of problems you're having. That
code
works perfectly: I ran it to ensure that what I suggested would work.
There
is one change that's required on newer versions of Access, though. Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference set to
the
DAO library. With any code module open, select Tools | References from
the
menu bar, scroll through the list of available references until you find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields and table for
the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed" some
out.
Finally got to the code and the entire statement is too long. Tried to
break
it up into three lines and now I am getting "end of statement" errors.
I don't want to keep pestering...is there anywhere I can go for these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more appropriate,
but
there
is
no value, such as "Owner", to let the module know when to create
the
string.
The values in the Detail column are all different. There is,
however, a
column in the table which lets the user know how many detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The Access
Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many other
fields).
Also
listed as part of the table are the detail codes for the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail codes,
WQF
appears
five
times in one column and the detail codes appear once in
another
column,
one
detail code each line. I need to go from vertical to
horizontal.
How
can I
get all the detail codes for each package into one line
(record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
D

Douglas J. Steele

Do not change the function! It works as is: I wouldn't have posted the
formula I did if I wasn't able to get it working in my sample database. The
function doesn't need changes for your usage. vForFldVal in what I gave you
is [Pkg]. It's a variant because there's no way to know whether you're going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg, fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to put a
double quote inside a string, you need to double the quote symbol. One of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Okay.
Added the quotes. Compiled it and received the message that the function
could not be found. It is the ONLY function in the db so I took the table
and
the module and the macro to run the module and moved it to a new db.
Compiled
it there and received the message that there is the wrong number of
arguments. Went to the area where the function is declared and removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the function
declarations there are four declarations. In the SQL statement, there are
four arguments except for Expr1. Could that have something to do with it?

There are many Access users here but they use high level queries and no
coding so I am basically alone on this. Thank you for your help.

Douglas J. Steele said:
It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Okay. I reset the statements to include "DAO". I went into References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax
error.

I receive a syntax error. The error starts at loSQL and ends at AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help. (This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're having.
That
code
works perfectly: I ran it to ensure that what I suggested would work.
There
is one change that's required on newer versions of Access, though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference set
to
the
DAO library. With any code module open, select Tools | References from
the
menu bar, scroll through the list of available references until you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields and table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed"
some
out.
Finally got to the code and the entire statement is too long. Tried
to
break
it up into three lines and now I am getting "end of statement"
errors.
I don't want to keep pestering...is there anywhere I can go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more
appropriate,
but
there
is
no value, such as "Owner", to let the module know when to
create
the
string.
The values in the Detail column are all different. There is,
however, a
column in the table which lets the user know how many detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The Access
Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many
other
fields).
Also
listed as part of the table are the detail codes for the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail codes,
WQF
appears
five
times in one column and the detail codes appear once in
another
column,
one
detail code each line. I need to go from vertical to
horizontal.
How
can I
get all the detail codes for each package into one line
(record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
G

Guest

Yes, after rereading your directions initially, I found the typo and fixed
it. I will get back to this and see what my issue is within the code.

Thanks for your help and your patience. I will let you know what has
happened one way or another.

Douglas J. Steele said:
Do not change the function! It works as is: I wouldn't have posted the
formula I did if I wasn't able to get it working in my sample database. The
function doesn't need changes for your usage. vForFldVal in what I gave you
is [Pkg]. It's a variant because there's no way to know whether you're going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg, fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to put a
double quote inside a string, you need to double the quote symbol. One of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Okay.
Added the quotes. Compiled it and received the message that the function
could not be found. It is the ONLY function in the db so I took the table
and
the module and the macro to run the module and moved it to a new db.
Compiled
it there and received the message that there is the wrong number of
arguments. Went to the area where the function is declared and removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the function
declarations there are four declarations. In the SQL statement, there are
four arguments except for Expr1. Could that have something to do with it?

There are many Access users here but they use high level queries and no
coding so I am basically alone on this. Thank you for your help.

Douglas J. Steele said:
It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax
error.

I receive a syntax error. The error starts at loSQL and ends at AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help. (This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're having.
That
code
works perfectly: I ran it to ensure that what I suggested would work.
There
is one change that's required on newer versions of Access, though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference set
to
the
DAO library. With any code module open, select Tools | References from
the
menu bar, scroll through the list of available references until you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields and table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed"
some
out.
Finally got to the code and the entire statement is too long. Tried
to
break
it up into three lines and now I am getting "end of statement"
errors.
I don't want to keep pestering...is there anywhere I can go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more
appropriate,
but
there
is
no value, such as "Owner", to let the module know when to
create
the
string.
The values in the Detail column are all different. There is,
however, a
column in the table which lets the user know how many detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The Access
Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many
other
fields).
Also
listed as part of the table are the detail codes for the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail codes,
WQF
appears
five
times in one column and the detail codes appear once in
another
column,
one
detail code each line. I need to go from vertical to
horizontal.
How
can I
get all the detail codes for each package into one line
(record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
G

Guest

Yes. I get the statement using Debug.Print.

Now, when I compile I am getting a Constant Expression Required error
message at the first 'cQ' in the first select statement.

Danu said:
Yes, after rereading your directions initially, I found the typo and fixed
it. I will get back to this and see what my issue is within the code.

Thanks for your help and your patience. I will let you know what has
happened one way or another.

Douglas J. Steele said:
Do not change the function! It works as is: I wouldn't have posted the
formula I did if I wasn't able to get it working in my sample database. The
function doesn't need changes for your usage. vForFldVal in what I gave you
is [Pkg]. It's a variant because there's no way to know whether you're going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg, fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to put a
double quote inside a string, you need to double the quote symbol. One of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Okay.
Added the quotes. Compiled it and received the message that the function
could not be found. It is the ONLY function in the db so I took the table
and
the module and the macro to run the module and moved it to a new db.
Compiled
it there and received the message that there is the wrong number of
arguments. Went to the area where the function is declared and removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the function
declarations there are four declarations. In the SQL statement, there are
four arguments except for Expr1. Could that have something to do with it?

There are many Access users here but they use high level queries and no
coding so I am basically alone on this. Thank you for your help.

:

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax
error.

I receive a syntax error. The error starts at loSQL and ends at AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help. (This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're having.
That
code
works perfectly: I ran it to ensure that what I suggested would work.
There
is one change that's required on newer versions of Access, though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference set
to
the
DAO library. With any code module open, select Tools | References from
the
menu bar, scroll through the list of available references until you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields and table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors. "Remmed"
some
out.
Finally got to the code and the entire statement is too long. Tried
to
break
it up into three lines and now I am getting "end of statement"
errors.
I don't want to keep pestering...is there anywhere I can go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more
appropriate,
but
there
is
no value, such as "Owner", to let the module know when to
create
the
string.
The values in the Detail column are all different. There is,
however, a
column in the table which lets the user know how many detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The Access
Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many
other
fields).
Also
listed as part of the table are the detail codes for the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail codes,
WQF
appears
five
times in one column and the detail codes appear once in
another
column,
one
detail code each line. I need to go from vertical to
horizontal.
How
can I
get all the detail codes for each package into one line
(record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
D

Douglas J. Steele

Did you copy-and-paste from the webpage, or did you retype?

cQ is defined as

Const cQ = """"

That's 4 double quotes in a row.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Yes. I get the statement using Debug.Print.

Now, when I compile I am getting a Constant Expression Required error
message at the first 'cQ' in the first select statement.

Danu said:
Yes, after rereading your directions initially, I found the typo and
fixed
it. I will get back to this and see what my issue is within the code.

Thanks for your help and your patience. I will let you know what has
happened one way or another.

Douglas J. Steele said:
Do not change the function! It works as is: I wouldn't have posted the
formula I did if I wasn't able to get it working in my sample database.
The
function doesn't need changes for your usage. vForFldVal in what I gave
you
is [Pkg]. It's a variant because there's no way to know whether you're
going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to put
a
double quote inside a string, you need to double the quote symbol. One
of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay.
Added the quotes. Compiled it and received the message that the
function
could not be found. It is the ONLY function in the db so I took the
table
and
the module and the macro to run the module and moved it to a new db.
Compiled
it there and received the message that there is the wrong number of
arguments. Went to the area where the function is declared and
removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the
function
declarations there are four declarations. In the SQL statement, there
are
four arguments except for Expr1. Could that have something to do with
it?

There are many Access users here but they use high level queries and
no
coding so I am basically alone on this. Thank you for your help.

:

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need
to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into
References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax
error.

I receive a syntax error. The error starts at loSQL and ends at
AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an
end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help.
(This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I
had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're
having.
That
code
works perfectly: I ran it to ensure that what I suggested would
work.
There
is one change that's required on newer versions of Access,
though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference
set
to
the
DAO library. With any code module open, select Tools | References
from
the
menu bar, scroll through the list of available references until
you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields and
table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors.
"Remmed"
some
out.
Finally got to the code and the entire statement is too long.
Tried
to
break
it up into three lines and now I am getting "end of statement"
errors.
I don't want to keep pestering...is there anywhere I can go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more
appropriate,
but
there
is
no value, such as "Owner", to let the module know when to
create
the
string.
The values in the Detail column are all different. There
is,
however, a
column in the table which lets the user know how many
detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at
http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The
Access
Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table with many package codes (as well as many
other
fields).
Also
listed as part of the table are the detail codes for
the
packages.
i.e.,
if
there is a package code of "WQF" and it has 5 detail
codes,
WQF
appears
five
times in one column and the detail codes appear once
in
another
column,
one
detail code each line. I need to go from vertical to
horizontal.
How
can I
get all the detail codes for each package into one
line
(record).
There
are
MANY.

As always, your help is appreciated.

- Danu
 
G

Guest

I copied and pasted...
But I will go in again and "rewrite" 4 double quotes.

Douglas J. Steele said:
Did you copy-and-paste from the webpage, or did you retype?

cQ is defined as

Const cQ = """"

That's 4 double quotes in a row.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Yes. I get the statement using Debug.Print.

Now, when I compile I am getting a Constant Expression Required error
message at the first 'cQ' in the first select statement.

Danu said:
Yes, after rereading your directions initially, I found the typo and
fixed
it. I will get back to this and see what my issue is within the code.

Thanks for your help and your patience. I will let you know what has
happened one way or another.

:

Do not change the function! It works as is: I wouldn't have posted the
formula I did if I wasn't able to get it working in my sample database.
The
function doesn't need changes for your usage. vForFldVal in what I gave
you
is [Pkg]. It's a variant because there's no way to know whether you're
going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to put
a
double quote inside a string, you need to double the quote symbol. One
of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay.
Added the quotes. Compiled it and received the message that the
function
could not be found. It is the ONLY function in the db so I took the
table
and
the module and the macro to run the module and moved it to a new db.
Compiled
it there and received the message that there is the wrong number of
arguments. Went to the area where the function is declared and
removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the
function
declarations there are four declarations. In the SQL statement, there
are
four arguments except for Expr1. Could that have something to do with
it?

There are many Access users here but they use high level queries and
no
coding so I am basically alone on this. Thank you for your help.

:

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need
to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into
References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax
error.

I receive a syntax error. The error starts at loSQL and ends at
AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an
end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help.
(This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I
had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're
having.
That
code
works perfectly: I ran it to ensure that what I suggested would
work.
There
is one change that's required on newer versions of Access,
though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference
set
to
the
DAO library. With any code module open, select Tools | References
from
the
menu bar, scroll through the list of available references until
you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields and
table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors.
"Remmed"
some
out.
Finally got to the code and the entire statement is too long.
Tried
to
break
it up into three lines and now I am getting "end of statement"
errors.
I don't want to keep pestering...is there anywhere I can go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more
appropriate,
but
there
is
no value, such as "Owner", to let the module know when to
create
the
string.
The values in the Detail column are all different. There
is,
however, a
column in the table which lets the user know how many
detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at
http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The
Access
Web"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


news:[email protected]...
 
G

Guest

Entered """". Closed the module. Tried to rerun it from a macro. Received the
error message "The expression you entered has a function containing the wrong
number of arguments."

Function fConcatFld(stTable As String, _ = Data (table)
stForFld As String, _ = pkg (lookup value)
stFldToConcat As String, _ = code (field to concatenate)
stForFldType As String, _ = string (data type)
vForFldVal As Variant) _ = pkg (value on which to
return string
As String

loSQL = "SELECT DISTINCT Data.pkg, " & _
"fConcatFld(""Data"",""pkg"",""code"",""String"",[pkg]) " & _
"AS Expr1 FROM Data"

Aren't all the arguments accounted for?

Danu said:
I copied and pasted...
But I will go in again and "rewrite" 4 double quotes.

Douglas J. Steele said:
Did you copy-and-paste from the webpage, or did you retype?

cQ is defined as

Const cQ = """"

That's 4 double quotes in a row.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Yes. I get the statement using Debug.Print.

Now, when I compile I am getting a Constant Expression Required error
message at the first 'cQ' in the first select statement.

:

Yes, after rereading your directions initially, I found the typo and
fixed
it. I will get back to this and see what my issue is within the code.

Thanks for your help and your patience. I will let you know what has
happened one way or another.

:

Do not change the function! It works as is: I wouldn't have posted the
formula I did if I wasn't able to get it working in my sample database.
The
function doesn't need changes for your usage. vForFldVal in what I gave
you
is [Pkg]. It's a variant because there's no way to know whether you're
going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to put
a
double quote inside a string, you need to double the quote symbol. One
of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay.
Added the quotes. Compiled it and received the message that the
function
could not be found. It is the ONLY function in the db so I took the
table
and
the module and the macro to run the module and moved it to a new db.
Compiled
it there and received the message that there is the wrong number of
arguments. Went to the area where the function is declared and
removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the
function
declarations there are four declarations. In the SQL statement, there
are
four arguments except for Expr1. Could that have something to do with
it?

There are many Access users here but they use high level queries and
no
coding so I am basically alone on this. Thank you for your help.

:

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you need
to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into
References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data;

It is at this point I am receiving a compile error and/or a syntax
error.

I receive a syntax error. The error starts at loSQL and ends at
AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an
end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your help.
(This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and when? I
had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're
having.
That
code
works perfectly: I ran it to ensure that what I suggested would
work.
There
is one change that's required on newer versions of Access,
though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a reference
set
to
the
DAO library. With any code module open, select Tools | References
from
the
menu bar, scroll through the list of available references until
you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields and
table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors.
"Remmed"
some
out.
Finally got to the code and the entire statement is too long.
Tried
to
break
it up into three lines and now I am getting "end of statement"
errors.
I don't want to keep pestering...is there anywhere I can go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks, Doug. I think the second module is the more
appropriate,
but
there
is
no value, such as "Owner", to let the module know when to
create
the
string.
The values in the Detail column are all different. There
is,
however, a
column in the table which lets the user know how many
detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the string?

- Danu

:

Take a look at
http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at "The
Access
Web"
 
D

Douglas J. Steele

You've got loSQL defined: what are you doing with it?

What happens if you paste

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data

into a query and run the query?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Entered """". Closed the module. Tried to rerun it from a macro. Received
the
error message "The expression you entered has a function containing the
wrong
number of arguments."

Function fConcatFld(stTable As String, _ = Data (table)
stForFld As String, _ = pkg (lookup value)
stFldToConcat As String, _ = code (field to
concatenate)
stForFldType As String, _ = string (data type)
vForFldVal As Variant) _ = pkg (value on which to
return string
As String

loSQL = "SELECT DISTINCT Data.pkg, " & _
"fConcatFld(""Data"",""pkg"",""code"",""String"",[pkg]) " & _
"AS Expr1 FROM Data"

Aren't all the arguments accounted for?

Danu said:
I copied and pasted...
But I will go in again and "rewrite" 4 double quotes.

Douglas J. Steele said:
Did you copy-and-paste from the webpage, or did you retype?

cQ is defined as

Const cQ = """"

That's 4 double quotes in a row.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes. I get the statement using Debug.Print.

Now, when I compile I am getting a Constant Expression Required error
message at the first 'cQ' in the first select statement.

:

Yes, after rereading your directions initially, I found the typo and
fixed
it. I will get back to this and see what my issue is within the
code.

Thanks for your help and your patience. I will let you know what has
happened one way or another.

:

Do not change the function! It works as is: I wouldn't have posted
the
formula I did if I wasn't able to get it working in my sample
database.
The
function doesn't need changes for your usage. vForFldVal in what I
gave
you
is [Pkg]. It's a variant because there's no way to know whether
you're
going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate
Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to
put
a
double quote inside a string, you need to double the quote symbol.
One
of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay.
Added the quotes. Compiled it and received the message that the
function
could not be found. It is the ONLY function in the db so I took
the
table
and
the module and the macro to run the module and moved it to a new
db.
Compiled
it there and received the message that there is the wrong number
of
arguments. Went to the area where the function is declared and
removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the
function
declarations there are four declarations. In the SQL statement,
there
are
four arguments except for Expr1. Could that have something to do
with
it?

There are many Access users here but they use high level queries
and
no
coding so I am basically alone on this. Thank you for your help.

:

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you
need
to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into
References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM
Data;

It is at this point I am receiving a compile error and/or a
syntax
error.

I receive a syntax error. The error starts at loSQL and ends
at
AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an
end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your
help.
(This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and
when? I
had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're
having.
That
code
works perfectly: I ran it to ensure that what I suggested
would
work.
There
is one change that's required on newer versions of Access,
though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a
reference
set
to
the
DAO library. With any code module open, select Tools |
References
from
the
menu bar, scroll through the list of available references
until
you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields
and
table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors.
"Remmed"
some
out.
Finally got to the code and the entire statement is too
long.
Tried
to
break
it up into three lines and now I am getting "end of
statement"
errors.
I don't want to keep pestering...is there anywhere I can
go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm sorry. I'd like a record to look like:
QWF 33,76,12
MNO 48,12
XYZ 82,22,34,87,77

(not necessarily using a comma as a separator)

:

What are you expecting to see given that data?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message
Thanks, Doug. I think the second module is the more
appropriate,
but
there
is
no value, such as "Owner", to let the module know
when to
create
the
string.
The values in the Detail column are all different.
There
is,
however, a
column in the table which lets the user know how
many
detail
codes
are
in
each package.

PKG AMT CODE
QWF 3 33
QWF 3 76
QWF 3 12
MNO 2 48
MNO 2 12
XYZ 5 82
XYZ 5 22
XYZ 5 34
XYZ 5 87
XYZ 5 77

Can that field be used as a flag to create the
string?

- Danu

:

Take a look at
http://www.mvps.org/access/modules/mdl0004.htm
and/or
http://www.mvps.org/access/modules/mdl0008.htm at
"The
Access
Web"
 
G

Guest

I tried that during one of the many iterations. It goes to "cQ" in the
function in the first Select case. Error message is Compile Error/Constant
Expression Required. But cQ is declared as Const cQ = """"

Douglas J. Steele said:
You've got loSQL defined: what are you doing with it?

What happens if you paste

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data

into a query and run the query?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Entered """". Closed the module. Tried to rerun it from a macro. Received
the
error message "The expression you entered has a function containing the
wrong
number of arguments."

Function fConcatFld(stTable As String, _ = Data (table)
stForFld As String, _ = pkg (lookup value)
stFldToConcat As String, _ = code (field to
concatenate)
stForFldType As String, _ = string (data type)
vForFldVal As Variant) _ = pkg (value on which to
return string
As String

loSQL = "SELECT DISTINCT Data.pkg, " & _
"fConcatFld(""Data"",""pkg"",""code"",""String"",[pkg]) " & _
"AS Expr1 FROM Data"

Aren't all the arguments accounted for?

Danu said:
I copied and pasted...
But I will go in again and "rewrite" 4 double quotes.

:

Did you copy-and-paste from the webpage, or did you retype?

cQ is defined as

Const cQ = """"

That's 4 double quotes in a row.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes. I get the statement using Debug.Print.

Now, when I compile I am getting a Constant Expression Required error
message at the first 'cQ' in the first select statement.

:

Yes, after rereading your directions initially, I found the typo and
fixed
it. I will get back to this and see what my issue is within the
code.

Thanks for your help and your patience. I will let you know what has
happened one way or another.

:

Do not change the function! It works as is: I wouldn't have posted
the
formula I did if I wasn't able to get it working in my sample
database.
The
function doesn't need changes for your usage. vForFldVal in what I
gave
you
is [Pkg]. It's a variant because there's no way to know whether
you're
going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate
Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said, to
put
a
double quote inside a string, you need to double the quote symbol.
One
of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay.
Added the quotes. Compiled it and received the message that the
function
could not be found. It is the ONLY function in the db so I took
the
table
and
the module and the macro to run the module and moved it to a new
db.
Compiled
it there and received the message that there is the wrong number
of
arguments. Went to the area where the function is declared and
removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In the
function
declarations there are four declarations. In the SQL statement,
there
are
four arguments except for Expr1. Could that have something to do
with
it?

There are many Access users here but they use high level queries
and
no
coding so I am basically alone on this. Thank you for your help.

:

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " & _
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string, you
need
to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into
References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM
Data;

It is at this point I am receiving a compile error and/or a
syntax
error.

I receive a syntax error. The error starts at loSQL and ends
at
AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an
end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your
help.
(This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and
when? I
had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems you're
having.
That
code
works perfectly: I ran it to ensure that what I suggested
would
work.
There
is one change that's required on newer versions of Access,
though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a
reference
set
to
the
DAO library. With any code module open, select Tools |
References
from
the
menu bar, scroll through the list of available references
until
you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my fields
and
table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors.
"Remmed"
some
out.
Finally got to the code and the entire statement is too
long.
Tried
to
break
it up into three lines and now I am getting "end of
statement"
errors.
I don't want to keep pestering...is there anywhere I can
go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;
 
D

Douglas J. Steele

Try removing the declaration for cQ and replacing the only line that uses it

loSQL = loSQL & "[" & stForFld & "] =" & cQ & vForFldVal & cQ

with

loSQL = loSQL & "[" & stForFld & "] =" & Chr$(34) & vForFldVal & Chr$(34)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
I tried that during one of the many iterations. It goes to "cQ" in the
function in the first Select case. Error message is Compile Error/Constant
Expression Required. But cQ is declared as Const cQ = """"

Douglas J. Steele said:
You've got loSQL defined: what are you doing with it?

What happens if you paste

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1 FROM Data

into a query and run the query?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Danu said:
Entered """". Closed the module. Tried to rerun it from a macro.
Received
the
error message "The expression you entered has a function containing the
wrong
number of arguments."

Function fConcatFld(stTable As String, _ = Data (table)
stForFld As String, _ = pkg (lookup value)
stFldToConcat As String, _ = code (field to
concatenate)
stForFldType As String, _ = string (data type)
vForFldVal As Variant) _ = pkg (value on which to
return string
As String

loSQL = "SELECT DISTINCT Data.pkg, " & _
"fConcatFld(""Data"",""pkg"",""code"",""String"",[pkg]) " & _
"AS Expr1 FROM Data"

Aren't all the arguments accounted for?

:

I copied and pasted...
But I will go in again and "rewrite" 4 double quotes.

:

Did you copy-and-paste from the webpage, or did you retype?

cQ is defined as

Const cQ = """"

That's 4 double quotes in a row.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Yes. I get the statement using Debug.Print.

Now, when I compile I am getting a Constant Expression Required
error
message at the first 'cQ' in the first select statement.

:

Yes, after rereading your directions initially, I found the typo
and
fixed
it. I will get back to this and see what my issue is within the
code.

Thanks for your help and your patience. I will let you know what
has
happened one way or another.

:

Do not change the function! It works as is: I wouldn't have
posted
the
formula I did if I wasn't able to get it working in my sample
database.
The
function doesn't need changes for your usage. vForFldVal in
what I
gave
you
is [Pkg]. It's a variant because there's no way to know whether
you're
going
to be passing it a numeric, text or date value.

Use Debug.Print to print the content of loSQL to the Immediate
Window
(Ctrl-G). What appears there should be:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS
Expr1 FROM Data

Note that there was a typo in what I posted earlier. As I said,
to
put
a
double quote inside a string, you need to double the quote
symbol.
One
of
the quote symbols wasn't doubled:

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code"",""String"",[Pkg]) " &
_
"AS Expr1 FROM Data"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay.
Added the quotes. Compiled it and received the message that
the
function
could not be found. It is the ONLY function in the db so I
took
the
table
and
the module and the macro to run the module and moved it to a
new
db.
Compiled
it there and received the message that there is the wrong
number
of
arguments. Went to the area where the function is declared
and
removed
vForFldVal As Variant because there is no variant.

Recompiled and still receiving wrong number of arguments. In
the
function
declarations there are four declarations. In the SQL
statement,
there
are
four arguments except for Expr1. Could that have something to
do
with
it?

There are many Access users here but they use high level
queries
and
no
coding so I am basically alone on this. Thank you for your
help.

:

It's because you're not setting the SQL string properly.

loSQL = "SELECT DISTINCT Data.Pkg, " & _
"fConcatFld(""Data"",""PKG"",""Code",""String"",[Pkg]) " &
_
"AS Expr1 FROM Data"

Note that in order to put quoted strings inside the string,
you
need
to
double the quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Okay. I reset the statements to include "DAO". I went into
References
and
added the MS 3.6 Object Library.

The SQL statement you sent earlier I setup as:

loSQL = SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg]) AS Expr1
FROM
Data;

It is at this point I am receiving a compile error and/or
a
syntax
error.

I receive a syntax error. The error starts at loSQL and
ends
at
AS,
which
also happens to be where the display breaks the statement.

If I put a set of quotes just before SELECT, I get an
end-of-statement
error
at "Data".

I seem to be going in circles. Again, thank you for your
help.
(This is
when
a good VBA book would come in very handy.)

How do you know which libraries should be referenced and
when? I
had no
idea
that the 3.6 Object Library was needed.

- Danu

:

I'm afraid I don't understand what sort of problems
you're
having.
That
code
works perfectly: I ran it to ensure that what I suggested
would
work.
There
is one change that's required on newer versions of
Access,
though.
Change

Dim lodb As Database, lors As Recordset

to

Dim lodb As DAO.Database, lors As DAO.Recordset

If that doesn't compile, then perhaps you don't have a
reference
set
to
the
DAO library. With any code module open, select Tools |
References
from
the
menu bar, scroll through the list of available references
until
you
find
the
one for Microsoft DAO 3.6 Object Library, and select it.

What "statement is too long"?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Okay. I "rewrote" the code below, substituting my
fields
and
table
for
the
fields and table in the code.
I tried to compile the code and got declaration errors.
"Remmed"
some
out.
Finally got to the code and the entire statement is too
long.
Tried
to
break
it up into three lines and now I am getting "end of
statement"
errors.
I don't want to keep pestering...is there anywhere I
can
go for
these
errors
which everyone must run into? (deep sigh)

Thanks.

:

Assuming the table is named "Data", use:

SELECT DISTINCT Data.Pkg,
fConcatFld("Data","PKG","Code","String",[Pkg])
AS
Expr1
FROM Data;
 

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