Query Names in a list box

D

Denver

i have unbound list box(lstQueries), cmdExport Excel and cmdEMAIL in a form.
I want to appear all the Queries i have in the list box? is this possible
how? do i need to use SQL or VBA?what code be look like or SQL be?
I want to export the selected query name in excel, is this possible?how to
wite the codes?
More often i will send thru email the selected queries i have in excel is it
possible that when I clik cmdEMAIL the selected queries will attached to
Outlook in Excel format? i try to see some example but in diffrenet way, i
want also to work in this way so that i can direcly paste them in outlook and
send to email.

thanks and any help are very appreciated

denver
 
D

Douglas J. Steele

Easiest way would be to use the following SQL as the RowSource:

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
ORDER BY [Name]

Be aware, though, that you may be surprised at what the list returns. For
example, if you've let the wizard build the RowSource for other forms or
controls, you'll find some oddly named queries in the list. If that's a
problem, you'lll have to add additional criteria to the WHERE clause to
ignore those queries.
 
D

Denver

sorry but im not a programmer i try using this SQL but no luck

SELECT [Name] = is it the name of my queries?
WHERE [TYPE]=5 = what is all about?
ORDER BY [Name] = can i replace SORT BY?

thanks


Douglas J. Steele said:
Easiest way would be to use the following SQL as the RowSource:

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
ORDER BY [Name]

Be aware, though, that you may be surprised at what the list returns. For
example, if you've let the wizard build the RowSource for other forms or
controls, you'll find some oddly named queries in the list. If that's a
problem, you'lll have to add additional criteria to the WHERE clause to
ignore those queries.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Denver said:
i have unbound list box(lstQueries), cmdExport Excel and cmdEMAIL in a
form.
I want to appear all the Queries i have in the list box? is this possible
how? do i need to use SQL or VBA?what code be look like or SQL be?
I want to export the selected query name in excel, is this possible?how to
wite the codes?
More often i will send thru email the selected queries i have in excel is
it
possible that when I clik cmdEMAIL the selected queries will attached to
Outlook in Excel format? i try to see some example but in diffrenet way, i
want also to work in this way so that i can direcly paste them in outlook
and
send to email.

thanks and any help are very appreciated

denver
 
J

John Spencer

What was posted was the SQL statement of a query.

Open a new query
DON'T add any tables
Switch to SQL view (MENU: View: SQL)
Paste or type in the statement.
If you want to see what that looks like in design view, switch back to design
view.



John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
sorry but im not a programmer i try using this SQL but no luck

SELECT [Name] = is it the name of my queries?
WHERE [TYPE]=5 = what is all about?
ORDER BY [Name] = can i replace SORT BY?

thanks


Douglas J. Steele said:
Easiest way would be to use the following SQL as the RowSource:

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
ORDER BY [Name]

Be aware, though, that you may be surprised at what the list returns. For
example, if you've let the wizard build the RowSource for other forms or
controls, you'll find some oddly named queries in the list. If that's a
problem, you'lll have to add additional criteria to the WHERE clause to
ignore those queries.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Denver said:
i have unbound list box(lstQueries), cmdExport Excel and cmdEMAIL in a
form.
I want to appear all the Queries i have in the list box? is this possible
how? do i need to use SQL or VBA?what code be look like or SQL be?
I want to export the selected query name in excel, is this possible?how to
wite the codes?
More often i will send thru email the selected queries i have in excel is
it
possible that when I clik cmdEMAIL the selected queries will attached to
Outlook in Excel format? i try to see some example but in diffrenet way, i
want also to work in this way so that i can direcly paste them in outlook
and
send to email.

thanks and any help are very appreciated

denver
 
D

Denver

John,

what i want to do is to have all the Queries i have in my list box
(lstQueries), and out from this list box a cmd button for cmdExport Excel and
cmdEMAIL so that i can export selected queries to excel or attached them in
my email using excel format.

why do i need to open a new query? if i only need to display all my queries
in a list box. I am using access 2003.

hope you understand my capacity im not really a programmer..

thanks anyway

denver

John Spencer said:
What was posted was the SQL statement of a query.

Open a new query
DON'T add any tables
Switch to SQL view (MENU: View: SQL)
Paste or type in the statement.
If you want to see what that looks like in design view, switch back to design
view.



John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
sorry but im not a programmer i try using this SQL but no luck

SELECT [Name] = is it the name of my queries?
WHERE [TYPE]=5 = what is all about?
ORDER BY [Name] = can i replace SORT BY?

thanks


Douglas J. Steele said:
Easiest way would be to use the following SQL as the RowSource:

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
ORDER BY [Name]

Be aware, though, that you may be surprised at what the list returns. For
example, if you've let the wizard build the RowSource for other forms or
controls, you'll find some oddly named queries in the list. If that's a
problem, you'lll have to add additional criteria to the WHERE clause to
ignore those queries.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


i have unbound list box(lstQueries), cmdExport Excel and cmdEMAIL in a
form.
I want to appear all the Queries i have in the list box? is this possible
how? do i need to use SQL or VBA?what code be look like or SQL be?
I want to export the selected query name in excel, is this possible?how to
wite the codes?
More often i will send thru email the selected queries i have in excel is
it
possible that when I clik cmdEMAIL the selected queries will attached to
Outlook in Excel format? i try to see some example but in diffrenet way, i
want also to work in this way so that i can direcly paste them in outlook
and
send to email.

thanks and any help are very appreciated

denver
 
D

Douglas J. Steele

The most common way to populate a list box is using a query. Make sure the
RowSourceType property is set to "Table/Query", and type the SQL I gave you
(all on one line) as the RowSource property.

John was telling you put it in a query so that a) you could see that it
worked and b) you could use that query as the RowSource property, rather
than typing the SQL as the RowSource property.

Now, if you do simply type the SQL as the RowSource property for your list
box, that query is still going to show up in the list of queries, which is
what I was alluding to at the end of my solution. For instance, I just added
that SQL to a list box named List0 on a form named Form2 and saved it. When
I reopened the form, there's a query named

~sq_cForm2~s1_cList0

in the list corresponding to that RowSource SQL. Since I suspect you won't
want queries like that in your list, you might use

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
AND [Name] NOT LIKE "~sq_*"
ORDER BY [Name]

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Denver said:
John,

what i want to do is to have all the Queries i have in my list box
(lstQueries), and out from this list box a cmd button for cmdExport Excel
and
cmdEMAIL so that i can export selected queries to excel or attached them
in
my email using excel format.

why do i need to open a new query? if i only need to display all my
queries
in a list box. I am using access 2003.

hope you understand my capacity im not really a programmer..

thanks anyway

denver

John Spencer said:
What was posted was the SQL statement of a query.

Open a new query
DON'T add any tables
Switch to SQL view (MENU: View: SQL)
Paste or type in the statement.
If you want to see what that looks like in design view, switch back to
design
view.

sorry but im not a programmer i try using this SQL but no luck

SELECT [Name] = is it the name of my queries?
WHERE [TYPE]=5 = what is all about?
ORDER BY [Name] = can i replace SORT BY?


:

Easiest way would be to use the following SQL as the RowSource:

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
ORDER BY [Name]

Be aware, though, that you may be surprised at what the list returns.
For
example, if you've let the wizard build the RowSource for other forms
or
controls, you'll find some oddly named queries in the list. If that's
a
problem, you'lll have to add additional criteria to the WHERE clause
to
ignore those queries.

i have unbound list box(lstQueries), cmdExport Excel and cmdEMAIL in
a
form.
I want to appear all the Queries i have in the list box? is this
possible
how? do i need to use SQL or VBA?what code be look like or SQL be?
I want to export the selected query name in excel, is this
possible?how to
wite the codes?
More often i will send thru email the selected queries i have in
excel is
it
possible that when I clik cmdEMAIL the selected queries will attached
to
Outlook in Excel format? i try to see some example but in diffrenet
way, i
want also to work in this way so that i can direcly paste them in
outlook
and
send to email.
 
D

Denver

thanks guys it works now..

denver
Douglas J. Steele said:
The most common way to populate a list box is using a query. Make sure the
RowSourceType property is set to "Table/Query", and type the SQL I gave you
(all on one line) as the RowSource property.

John was telling you put it in a query so that a) you could see that it
worked and b) you could use that query as the RowSource property, rather
than typing the SQL as the RowSource property.

Now, if you do simply type the SQL as the RowSource property for your list
box, that query is still going to show up in the list of queries, which is
what I was alluding to at the end of my solution. For instance, I just added
that SQL to a list box named List0 on a form named Form2 and saved it. When
I reopened the form, there's a query named

~sq_cForm2~s1_cList0

in the list corresponding to that RowSource SQL. Since I suspect you won't
want queries like that in your list, you might use

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
AND [Name] NOT LIKE "~sq_*"
ORDER BY [Name]

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Denver said:
John,

what i want to do is to have all the Queries i have in my list box
(lstQueries), and out from this list box a cmd button for cmdExport Excel
and
cmdEMAIL so that i can export selected queries to excel or attached them
in
my email using excel format.

why do i need to open a new query? if i only need to display all my
queries
in a list box. I am using access 2003.

hope you understand my capacity im not really a programmer..

thanks anyway

denver

John Spencer said:
What was posted was the SQL statement of a query.

Open a new query
DON'T add any tables
Switch to SQL view (MENU: View: SQL)
Paste or type in the statement.
If you want to see what that looks like in design view, switch back to
design
view.


Denver wrote:
sorry but im not a programmer i try using this SQL but no luck

SELECT [Name] = is it the name of my queries?
WHERE [TYPE]=5 = what is all about?
ORDER BY [Name] = can i replace SORT BY?


:

Easiest way would be to use the following SQL as the RowSource:

SELECT [Name]
FROM MSysObjects
WHERE [Type]=5
ORDER BY [Name]

Be aware, though, that you may be surprised at what the list returns.
For
example, if you've let the wizard build the RowSource for other forms
or
controls, you'll find some oddly named queries in the list. If that's
a
problem, you'lll have to add additional criteria to the WHERE clause
to
ignore those queries.

i have unbound list box(lstQueries), cmdExport Excel and cmdEMAIL in
a
form.
I want to appear all the Queries i have in the list box? is this
possible
how? do i need to use SQL or VBA?what code be look like or SQL be?
I want to export the selected query name in excel, is this
possible?how to
wite the codes?
More often i will send thru email the selected queries i have in
excel is
it
possible that when I clik cmdEMAIL the selected queries will attached
to
Outlook in Excel format? i try to see some example but in diffrenet
way, i
want also to work in this way so that i can direcly paste them in
outlook
and
send to email.
 

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