Hi,
I calculated the where clause of mij select statment in a variable,
how can I get the content of the variable in my select statment.
vb
if my variable condition contains "Model like txtModel and status like
txtStatus"
is there a way to past this beween a select statement?
Sure. Here is some sample code to fill a listbox with records from
two joined tables using user-supplied dates:
Dim sSELECT as string
Dim sWHERE as string
sSELECT ="SELECT [LName],[FName],[InvoiceNumber],[InvoiceDate],[Total]
FROM tblCustomers INNER JOIN tblSales ON tblCustomer.[CustomerNumber]
= tblSales.[CustomerNumber] "
sWHERE = "WHERE [InvoiceDate] >= #" & dInvoiceDateStart & "# AND
[InvoiceDate] <= #" & dInvoiceDateEnd & "#;"
ListBox1.RowSource = sSELECT & sWHERE
I tried it your way, but the only thing I get in my listbox is the
select statement, not the outcome of my select statement.
Thank you already,
Mieke- Hide quoted text -
The code in the example is good. It sounds like you need more
experience debugging. Judging by your example, you are using ADO. Is
this correct? Is your system setup to use DAO too? What version of
Access are you using?
When you tried my example, did you set the RowSourceType of the
listbox to Table/Query?
The easiest way to debug a SQL query is to enter it in the SQL view of
the query builder. To do this, click on the Query tab of the database
dialog, and select New. Then click Design View. Select the
appropriate table from the list, and click Add. Then click Close to
exit the table picker. Select View - > SQLView from the menu.
Replace the existing SQL query with the one you want to test. Then
select "View -> Datasheet View" from the menu. If there is an error,
the point where the error occurs will be highlighted. If no error is
encountered, you will see the resultant recordset. If the returned
recordset does not match what you expected, then you know to change
your SQL statement.
If you are building a SQL string in a program, then attach a code
break (Debug -> Toggle Break Point) to the line after you assign the
final portion of your SQL clause to the SQL string variable. Run the
code: it will stop at this line. Then bring up the debug window(Crtl-
G) and display the contents of the SQL variable with a print statement
(the question mark followed by the variable name will do).
After you hit enter, the contents of the variable will display in the
debug window. Finally, highlight the entire SQL statement (it should
be on a line by itself) and do a Ctrl-Insert. Then follow the
instructions above to create a new query, and open the SQL View. Do a
Shift - Insert to paste the SQL clause from the debug window to the
SQL View.
Like all things, it becomes easier with practice.- Tekst uit oorspronkelijk bericht niet weergeven -
- Tekst uit oorspronkelijk bericht weergeven -