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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with my sql statement (date selection) in Data Report ? 1

Status
Not open for further replies.

awinnn

MIS
Jul 21, 2003
166
0
0
MY
Hi,
I have DtPicker1, DtPicker2 and cmd_OK on Form1.
I want to display report based on date selection.
this is code in Form1,
------------------------------------------
Private Sub cmd_OK_Click()
Report1.Show
End Sub

Private Sub Form_Load()
DTPicker1.Value = CDate("01/01/2000")
DTPicker2.Value = CDate("12/21/2000")
End Sub
------------------------------------------

and this is code in Report1,
------------------------------------------
Private Sub DataReport_Initialize()
Dim strSQL As String
Dim strTo As String
Dim strFrom As String
Dim oConn As New ADODB.Connection
Dim oRS As New ADODB.Recordset

oConn.CursorLocation = adUseClient
oConn.ConnectionString = DataEnvironment1.Connection1
oConn.Open

With Form1
strTo = .DTPicker1.Value
strFrom = .DTPicker2.Value
End With
Report1.Title = "From: " & strFrom & " To: " & strTo
strSQL = "(SELECT [courier query].* FROM [courier query]
WHERE date BETWEEN #" & strFrom & "# AND #" &
strTo & "# )AS Command4"
oRS.Open strSQL, oConn, adOpenForwardOnly 'line 1
Set Report1.DataSource = oRS
End Sub
------------------------------------------

i've set the Connection1..but when i click the button, there was an error,
'Syntax error in union query'.

the error highlights on line 1.

any idea?
thanx..
 
Try changing strSQL to the following:
Code:
   strSQL = "SELECT [courier query].* FROM [courier query] 
             WHERE date BETWEEN #" & strFrom & "# AND #" & 
             strTo & "#" [\code]
This should work.  The brackets around the Select statement followed by the "AS Command4" confuse it into thinking this is a UNION sql statement.

Rick
 
Hi Rick,
Thanx for your help..it works..:)

* for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top