Discussion Locked

Assign a column variable in SQL

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Using Access2K. -- Need help with writing the following SQL statement which is Making a table based on another query. The first query has many columns and I only want to make the new table with a one specifically selected column.

SELECT [qry_#2_DeptTotals_GROUP_Plan].Major_Account_Group, [qry_#2_DeptTotals_GROUP_Plan].CC_ID, [qry_#2_DeptTotals_GROUP_Plan].Nov_Tot INTO tblCostCtrMonthbyGroup
FROM [qry_#2_DeptTotals_GROUP_Plan];

The SQL statement will reside on a form and will launch (DoCmd.RunSQL) from a command button

The column to be returned for the new table will be the value from a Text box control that is on the form.

I want to replace the following in the above statement:

[qry_#2_DeptTotals_GROUP_Plan].Nov_Tot

with a variable that gets its value from a Text Box control on the form.

Thanks,
Rich

3 replies

by john_wills

In VBA, after click of an appropriate button, or on losing focus on the control:
DoCmd.RunSQL "Select Major_Account_Group,CC_ID,'" & Me.ControlText & "' AS Nov_Tot_Substitute INTO tblCostCtrMonthlyGroup FROM qry_#2_etc;"

by richtee

John -- Adjusted your answer to my environment and it worked like a charm. -- Thanks. -- Rich

This discussion is closed to new replies.