n1a2v3i3n
Programmer
- Jan 19, 2009
- 18
I want to generate data report through a Query. I have used the following code
Private Sub Command7_Click()
Dim Adodc1 As New ADODB.Recordset
Dim str As String
Dim st As String
Dim good As String
Dim a, b As Date
good = Chr(35)
st = "EC11"
a = Format(Date + 15, "dd/mm/yyyy")
b = Format(Date + 30, "dd/mm/yyyy")
MsgBox " Start date " & a
MsgBox " End Date " & b
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Vechdetail.mdb;Persist Security Info=False"
st = " select Vehicle, insucom, invaf, invat from trafdetails where invat between " & good & a & good & "and" & good & b & good & ""
Adodc1.Open st, str, adOpenDynamic, adLockOptimistic
Do While Not Adodc1.EOF
MsgBox " Record Found " & Adodc1(0) & " " & Adodc1(1) & " " & Adodc1(2) & " " & Adodc1(3)
Adodc1.MoveNext
Loop
Set dr1.DataSource = Adodc1
dr1.Show
End Sub
Using above the record shows me all the record that are in the database instead of showing the selected records based on the query.
Please help me on how do i display the required records with help of query.
Private Sub Command7_Click()
Dim Adodc1 As New ADODB.Recordset
Dim str As String
Dim st As String
Dim good As String
Dim a, b As Date
good = Chr(35)
st = "EC11"
a = Format(Date + 15, "dd/mm/yyyy")
b = Format(Date + 30, "dd/mm/yyyy")
MsgBox " Start date " & a
MsgBox " End Date " & b
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Vechdetail.mdb;Persist Security Info=False"
st = " select Vehicle, insucom, invaf, invat from trafdetails where invat between " & good & a & good & "and" & good & b & good & ""
Adodc1.Open st, str, adOpenDynamic, adLockOptimistic
Do While Not Adodc1.EOF
MsgBox " Record Found " & Adodc1(0) & " " & Adodc1(1) & " " & Adodc1(2) & " " & Adodc1(3)
Adodc1.MoveNext
Loop
Set dr1.DataSource = Adodc1
dr1.Show
End Sub
Using above the record shows me all the record that are in the database instead of showing the selected records based on the query.
Please help me on how do i display the required records with help of query.