Export query to Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this query:
SELECT PHQ.SSN, PHQ.PHQDate, PHQ.PHQTOT
FROM PHQ
WHERE (((PHQ.SSN)=[whichSSN]));


How can I export this to Excel programaticlly?
 
You will want to use the TransferSpreadsheet method. You will find detailed
instructions in VBA editor Help. The TransferSpreadsheet method, however,
will not accept an SQL string as the Table Name argument. You will need to
create a stored query with a parameter for the SSN. If you run this from a
form, you can reference the control on the form where the SSN is carried for
the parameter value.
 
How do you create a stored query? And then use that to do the export?

Klatuu said:
You will want to use the TransferSpreadsheet method. You will find detailed
instructions in VBA editor Help. The TransferSpreadsheet method, however,
will not accept an SQL string as the Table Name argument. You will need to
create a stored query with a parameter for the SSN. If you run this from a
form, you can reference the control on the form where the SSN is carried for
the parameter value.

pokdbz said:
I have this query:
SELECT PHQ.SSN, PHQ.PHQDate, PHQ.PHQTOT
FROM PHQ
WHERE (((PHQ.SSN)=[whichSSN]));


How can I export this to Excel programaticlly?
 
From the database window, select Queries, Click New. It will ask you what
table or query you want to use for the query. Select the table. Then in the
query builder, select your fields. Use the Criteria row to put your Where
condition in, without the word Where. If you want to reference a control on
your form to pass the SSN, it would look something like:

Forms!frmMyFormName!WhichSSN

Read VBA Help on the TransferSpreadsheet method for details on it's syntax.

To call it, create a command button on your form and put the code for the
TransferSpreadsheet in the Click event.

pokdbz said:
How do you create a stored query? And then use that to do the export?

Klatuu said:
You will want to use the TransferSpreadsheet method. You will find detailed
instructions in VBA editor Help. The TransferSpreadsheet method, however,
will not accept an SQL string as the Table Name argument. You will need to
create a stored query with a parameter for the SSN. If you run this from a
form, you can reference the control on the form where the SSN is carried for
the parameter value.

pokdbz said:
I have this query:
SELECT PHQ.SSN, PHQ.PHQDate, PHQ.PHQTOT
FROM PHQ
WHERE (((PHQ.SSN)=[whichSSN]));


How can I export this to Excel programaticlly?
 
Worked perfect thanks

Klatuu said:
From the database window, select Queries, Click New. It will ask you what
table or query you want to use for the query. Select the table. Then in the
query builder, select your fields. Use the Criteria row to put your Where
condition in, without the word Where. If you want to reference a control on
your form to pass the SSN, it would look something like:

Forms!frmMyFormName!WhichSSN

Read VBA Help on the TransferSpreadsheet method for details on it's syntax.

To call it, create a command button on your form and put the code for the
TransferSpreadsheet in the Click event.

pokdbz said:
How do you create a stored query? And then use that to do the export?

Klatuu said:
You will want to use the TransferSpreadsheet method. You will find detailed
instructions in VBA editor Help. The TransferSpreadsheet method, however,
will not accept an SQL string as the Table Name argument. You will need to
create a stored query with a parameter for the SSN. If you run this from a
form, you can reference the control on the form where the SSN is carried for
the parameter value.

:

I have this query:
SELECT PHQ.SSN, PHQ.PHQDate, PHQ.PHQTOT
FROM PHQ
WHERE (((PHQ.SSN)=[whichSSN]));


How can I export this to Excel programaticlly?
 
Back
Top