code to change bound report control

C

Chrisx

Hi,
I have written code to modify a query based on a table
that the user creates from excel. This query is used in a
report. The table only contains 1 column, but in case the
user creates the table with a different column name, I
want to make sure that the query and report use the
correct names.
The user keys the table name into a form. The form
runs the code to modify the query, and eventually, run the
report.
I included the code that I have to match the query to
the table that the user enters into my form, but not sure
how to change the control in the report to match the
column in the query.
Can anybody help me with this next part?


Dim qdf As QueryDef
Dim sqlSTR As String

Set qdf = CurrentDb.QueryDefs("User_Qry")
sqlSTR = "Select * from [" & Forms![XREF_Form]!UserTbl
& "]"
qdf.SQL = sqlSTR
qdf.Close
 
B

Bas Cost Budde

Chrisx said:
Hi,
I have written code to modify a query based on a table
that the user creates from excel. This query is used in a
report. The table only contains 1 column, but in case the
user creates the table with a different column name, I
want to make sure that the query and report use the
correct names.
The user keys the table name into a form. The form
runs the code to modify the query, and eventually, run the
report.
I included the code that I have to match the query to
the table that the user enters into my form, but not sure
how to change the control in the report to match the
column in the query.
Can anybody help me with this next part?


Dim qdf As QueryDef
Dim sqlSTR As String

Set qdf = CurrentDb.QueryDefs("User_Qry")
sqlSTR = "Select * from [" & Forms![XREF_Form]!UserTbl
& "]"
qdf.SQL = sqlSTR
qdf.Close

.... and if you don't change the control in the report at all, but add a
label to the SQL statement?

SELECT thatExcelField AS yourReportFieldName etc..

You can find the actual name of the field in the table by examining the
Fields collection (expecting one field as I understand your situation)
of the TableDef object.
 
B

Bas Cost Budde

Chrisx said:
I can't seem to read the reply. It just says message
unavailable.

It seems my news reader is broken.
I said:

.... and if you don't change the control in the report at all, but add a
label to the SQL statement?

SELECT thatExcelField AS yourReportFieldName etc..

You can find the actual name of the field in the table by examining the
Fields collection (expecting one field as I understand your situation)
of the TableDef object.
 

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