Create a virtual table for form RecordSource
-
I am using a SQL statement to fill the contents of a subform's RecordSource:
Me.sub_NestedSchedule.Form.RecordSource = strMySqlStatement
How can I create a "virtual table" that has the empty string for all 6 of its fields and force that into my subform's RecordSource? I want to initialize the subform during OnLoad and have the empty string. Thanks, JJM
-
I am using a SQL statement to fill the contents of a subform's RecordSource:
Me.sub_NestedSchedule.Form.RecordSource = strMySqlStatement
How can I create a "virtual table" that has the empty string for all 6 of its fields and force that into my subform's RecordSource? I want to initialize the subform during OnLoad and have the empty string. Thanks, JJM
Not sure how you are using the sql string but if you query the table with a nonsense where clause you will get back and empty data table.
Select * from MyTable where IDField = 0
Select * from MyTable where 1=1
These will return an empty datatable
Never underestimate the power of human stupidity RAH
-
Not sure how you are using the sql string but if you query the table with a nonsense where clause you will get back and empty data table.
Select * from MyTable where IDField = 0
Select * from MyTable where 1=1
These will return an empty datatable
Never underestimate the power of human stupidity RAH
Select * from MyTable where 1=1
I think the previous SQL statement will return all rows in table I think this is what you want to say
Select * from MyTable where 1=2
In addition to those solutions we can use
Select top 0 * from MyTable
-
Select * from MyTable where 1=1
I think the previous SQL statement will return all rows in table I think this is what you want to say
Select * from MyTable where 1=2
In addition to those solutions we can use
Select top 0 * from MyTable
YES! That's the ticket... To initialize my RecordSource with an empty table that has the EmptyString instead of "#Name?" appearing, here is what I did. I used a table that had a text data field (Label) and has as default value the empty string. I know that this table (tbl_MyHandyTable) will always be present. So I did this:
strSQL_subform = "SELECT [Lable] AS field1, [Label] AS field2, "
strSQL_subform = strSQL_subform + "[Label] AS field-N, "
...
strSQL_subform = strSQL_subform + "FROM [tbl_MyHandyTable] "
strSQL_subform = strSQL_subform + "WHERE 1=2;"'initialize the record source with the empty table of EmptyStrings
Me.RecordSource = strSQL_subformThanks all!
-
Not sure how you are using the sql string but if you query the table with a nonsense where clause you will get back and empty data table.
Select * from MyTable where IDField = 0
Select * from MyTable where 1=1
These will return an empty datatable
Never underestimate the power of human stupidity RAH
Thanks, i understood what you were getting at and arrived at my solution - following post.
-
I am using a SQL statement to fill the contents of a subform's RecordSource:
Me.sub_NestedSchedule.Form.RecordSource = strMySqlStatement
How can I create a "virtual table" that has the empty string for all 6 of its fields and force that into my subform's RecordSource? I want to initialize the subform during OnLoad and have the empty string. Thanks, JJM
The
ExecuteReader()
function of a command can receive aCommandBehavior
parameter. Why not useCommandBehavior.SchemaOnly
orCommandBehavior.KeyInfo
? E.g.SqlCommand cmd = new SqlCommand("SELECT \* FROM MyTable"); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);