![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
With the statement in SQL SELECT * FROM firstdatatable I can use the query to pull out data from firstdatatable. Say I also had: firstdatatable seconddatatable thirddatatable fourthdatatable And a combo box that put into a Global Variable declared as a string the valuw "first","second", "third", fourth. Could I add the element datatable to the stored element first, second etc to call up the table required, so that if the combo box allocated "third" the SQL would be: SELECT * FROM "GBL_Combo_Output & 'datatable'" Such that I could use this query and drag data from the four different tables depending on the setting of the combo box? I have had a google, but most of the answers revolve around doing this sort of operation using the WHERE Criteria as opposed to just bringing up the whole table. I want to use this select query for reporting and data entry on completion, to read from and amend the table which corresponds to the combo output. Thanks J |
#3
| |||
| |||
|
|
In the afterupdate event of the combo and assuming the combo name is MyCombo and the value you want is in the second column (indexes start at 0). Dim strSQL As String 'define string strSQL = "Select * From " & Me.MyCombo.Column(1) 'tbl name 2nd col Me.Recordsource = strSQL 'change this forms recordsource or Me.AnotherComboName.Rowsource = strSQL 'change a rowsource in a combo Check out Column, Rowsource, and Recordsource in help. |
#4
| |||
| |||
|
|
Hi, I don't want to use the combobox directly to drive the query, only to set the global variable so that any query run will use the Global Variable. The explanation was generic. To be more specific say I had: SwiftsureDataTable SovereignDataTable SceptreDataTable The drop down box will have as its bound column, Swiftsure, Sovereign Sceptre etc, and I wish to pull the data from the relevant table and use the SQL query as a source query for generating reports,updating data, as each table, although having the same structure will e at different levels of maturity I am asking in effect, how to add "Swiftsure" to "DataTable" in the SQL Statement so I get: SELECT * FROM 'Swiftsure' & 'Datatable' If that is indeed possible, I can't use the strSQL as I want to make the query available to other queries, and want to just make the combo box output the variable. I know in query parameters to get a Global Variable as a criteria I have to use a function GetBoatName() for example. Thanks Still confused. You could run this code from a code module. |
#5
| |||
| |||
|
|
Hi, I don't want to use the combobox directly to drive the query, only to set the global variable so that any query run will use the Global Variable. The explanation was generic. To be more specific say I had: SwiftsureDataTable SovereignDataTable SceptreDataTable The drop down box will have as its bound column, Swiftsure, Sovereign Sceptre etc, and I wish to pull the data from the relevant table and use the SQL query as a source query for generating reports,updating data, as each table, although having the same structure will e at different levels of maturity I am asking in effect, how to add "Swiftsure" to "DataTable" in the SQL Statement so I get: SELECT * FROM 'Swiftsure' & 'Datatable' If that is indeed possible, I can't use the strSQL as I want to make the query available to other queries, and want to just make the combo box output the variable. I know in query parameters to get a Global Variable as a criteria I have to use a function GetBoatName() for example. Thanks J In the afterupdate event of the combo and assuming the combo name is MyCombo and the value you want is in the second column (indexes start at 0). Dim strSQL As String 'define string strSQL = "Select * From " & Me.MyCombo.Column(1) 'tbl name 2nd col Me.Recordsource = strSQL 'change this forms recordsource or Me.AnotherComboName.Rowsource = strSQL 'change a rowsource in a combo Check out Column, Rowsource, and Recordsource in help. |
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Reading your response, it would appear that there is no way to concatenate the Global Variable with the fixed part of the table data i.e. Swiftsure & DataTable to generate the query? I can't use union as I do need to edit the table, so it looks as if I will need to build a more complex form, get rid of the combo control and just allocate a command button to address each table directly. I have been googling heavily in between posts and I have seen loads of examples where the WHERE function is concatenated, but none at all where the table name is, so I guess it isn't possible. |
#9
| |||
| |||
|
|
Bob, Reading your response, it would appear that there is no way to concatenate the Global Variable with the fixed part of the table data i.e. Swiftsure & DataTable to generate the query? Yes, using VBA it is easily done. I suspect you're not getting the meaning |
|
I can't use union as I do need to edit the table, so it looks as if I will need to build a more complex form, get rid of the combo control and just allocate a command button to address each table directly. I have been googling heavily in between posts and I have seen loads of examples where the WHERE function is concatenated, but none at all where the table name is, so I guess it isn't possible. Of course concatenating the table name is possible.It's the same concept as |
![]() |
| Thread Tools | |
| Display Modes | |
| |