Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter and Sort in one SQL Statement

Status
Not open for further replies.

3535

Programmer
Dec 19, 1999
18
US
The line that say's: SQLStmt = SQLStmt & &quot; (Table1.Terr = &quot; & Me.Text59 & &quot; ) &quot; sets a filter to whatever terr(itory) number I input into Me.Text59.<br>
What I would like to do now is also add a Sort on DateField to the same SQLStmt.<br>
Final outcome would be a database displaying all, example Terr(itory) 8 sorted by DateField.<br>
Is this possible or am I asking too much of SQL? Thanks Ray<br>
<br>
Sub Refreshdata()<br>
Dim SQLStmt As String<br>
SQLStmt = &quot;SELECT * FROM Table1 WHERE&quot;<br>
If Me.Text59 &lt;&gt; &quot;&quot; Then<br>
SQLStmt = SQLStmt & &quot; (Table1.Terr = &quot; & Me.Text59 & &quot; ) &quot;<br>
End If<br>
MsgBox &quot; Me.text59 (a Number Field) = number &quot; & Me.Text59<br>
If Right(SQLStmt,5)&lt;&gt;&quot;WHERE&quot; Then Me.RecordSource = SQLStmt<br>
End Sub<br>
<br>
<br>
<br>

 
You are not asking too much of it, just build it up naturally.<br>
<br>
If me.text59 is null then you can concat it anyway!<br>
<br>
<br>
Sub Refreshdata()<br>
Dim SQLStmt As String<br>
SQLStmt = &quot;SELECT * FROM Table1 WHERE (Table1.Terr = &quot; & Me.Text59 & &quot; ) order by datefield asc;&quot;<br>
MsgBox &quot; Me.text59 (a Number Field) = number &quot; & Me.Text59<br>
If Right(SQLStmt,5)&lt;&gt;&quot;WHERE&quot; Then Me.RecordSource = SQLStmt<br>
End Sub<br>
<br>
Think this should work dependent on the rest of the fields etc.<br>
<br>

 
Really do appreciate your through response. Ray<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top