simple Sql statement not working

habbabub

Registered User.
Local time
Today, 04:27
Joined
Jan 24, 2008
Messages
73
i have an sql statement:

aa = "hello"

Tasklist.RowSource = "SELECT [Tasks].Staff_Name, [Tasks].Project_Title, [Tasks].Percentage_Complete FROM [Tasks] WHERE [Tasks].Date_Allocated < aa ORDER BY [Tasks].Staff_Name;"


how can i make it look the the data i put in "aa" rather than prompt a msg box asking for "aa"?
 
Tasklist.RowSource = "SELECT [Tasks].Staff_Name, [Tasks].Project_Title, [Tasks].Percentage_Complete FROM [Tasks] WHERE [Tasks].Date_Allocated < '" & aa & "' ORDER BY [Tasks].Staff_Name;"
 
hb,

If aa was a textbox on your form, this would do it.

Code:
Tasklist.RowSource = "SELECT [Tasks].Staff_Name, [Tasks].Project_Title, [Tasks].Percentage_Complete " & _
                     "FROM [Tasks] " & _
                     "WHERE [Tasks].Date_Allocated < #" & Me.aa & "# " & _
                     "ORDER BY [Tasks].Staff_Name;"


If aa was supplied by an InputBox in your code: <-- see Help for Inputbox

Code:
Tasklist.RowSource = "SELECT [Tasks].Staff_Name, [Tasks].Project_Title, [Tasks].Percentage_Complete " & _
                     "FROM [Tasks] " & _
                     "WHERE [Tasks].Date_Allocated < #" & aa & "# " & _
                     "ORDER BY [Tasks].Staff_Name;"

hth,
Wayne
 
HB,

"If aa was supplied by an InputBox in your code"

Or if aa was assigned a value in your code.
Wayne
 
I was wondering why Wayne surrounded the value with # until I noticed the field name. His method is correct if you're dealing with a date. I only looked at

aa = "hello"

so used the single quote, which is correct if the value is text. You don't want either one if the value is numeric. It's the data type of the field in the table that determines which is appropriate.
 

Users who are viewing this thread

Back
Top Bottom