|
-
Apr 13th, 2006, 06:58 AM
#1
Thread Starter
Member
How to find the date range in MS Access and display in MS Flex Grid?
How do i search the date range which can be specified by the user and all the records from these date range will be display in MSFlexGrid. Can someone help me with this??
Thanks.
-
Apr 13th, 2006, 07:15 AM
#2
Re: How to find the date range in MS Access and display in MS Flex Grid?
if it is Access use this query...
VB Code:
Sql = "Select * From <TableName> Where MyDate Between DateValue ('" & txtFromDate.Text & "') And DateValue ('" & txtToDate.Text & "')"
Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
i = 1
Do While Not Rs.EOF
FlexGrid.TextMatrix(i, 1) = Rs!FieldName1
FlexGrid.TextMatrix(i, 2) = Rs!FieldName2
FlexGrid.TextMatrix(i, 3) = Rs!FieldName3
' and so on
i = i + 1
Rs.MoveNext
Loop
Rs.Close
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Apr 13th, 2006, 09:22 AM
#3
Thread Starter
Member
Re: How to find the date range in MS Access and display in MS Flex Grid?
I'm having error on this line
Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
Run time error '424'
Object Required
Can somebody help me.
-
Apr 13th, 2006, 10:29 AM
#4
Thread Starter
Member
Re: How to find the date range in MS Access and display in MS Flex Grid?
Private Sub Form_Load()
Dim Sql
Dim Rs As Recordset
Dim Cn
Set Cn = New ADODB.Connection
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "control.mdb;" & "Persist Security Info=False"
Sql = "Select * From Kdata Where Tarikh Between DateValue ('" & txtFromDate.Text & "') And DateValue ('" & txtToDate.Text & "')"
Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
i = 1
Do While Not Rs.EOF
MSFlexGrid1.TextMatrix(i, 1) = Rs!No_Rujukan
MSFlexGrid1.TextMatrix(i, 2) = Rs!Tarikh
MSFlexGrid1.TextMatrix(i, 3) = Rs!Masa_Mula
' and so on
i = i + 1
Rs.MoveNext
Loop
Rs.Close
End Sub
What is wrong with this line " Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic "?? It is saying Run time error '91' Object variable or with bolck variable not set.
Please help.
-
Apr 13th, 2006, 10:33 AM
#5
Re: How to find the date range in MS Access and display in MS Flex Grid?
You need to create the recordset object with
Set rs = New ADODB.Recordset
Just like you did with the Connection object.
-
Apr 13th, 2006, 11:26 AM
#6
Thread Starter
Member
Re: How to find the date range in MS Access and display in MS Flex Grid?
Private Sub Form_Load()
Dim Sql
Dim Rs As Recordset
Dim Cn
Set Cn = New ADODB.Connection
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "control.mdb;" & "Persist Security Info=False"
Set Rs = New ADODB.Recordset
Sql = "Select * From Kdata Where Tarikh Between DateValue ('" & txtFromDate.Text & "') And DateValue ('" & txtToDate.Text & "')"
Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
i = 1
Do While Not Rs.EOF
MSFlexGrid1.TextMatrix(i, 1) = Rs!No_Rujukan
MSFlexGrid1.TextMatrix(i, 2) = Rs!Tarikh
MSFlexGrid1.TextMatrix(i, 3) = Rs!Masa_Mula
' and so on
i = i + 1
Rs.MoveNext
Loop
Rs.Close
End Sub
Now the error is
Run time error '-2147217913 (80040e07)'
Data type mismatch in criteria expression
Still the error is in this line Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
Please give me some suggestion.
-
Apr 13th, 2006, 11:45 AM
#7
Re: How to find the date range in MS Access and display in MS Flex Grid?
Since you are using MS Access I would change the DateValue part like this:
VB Code:
Sql = "Select * From Kdata Where Tarikh Between #'" & Formamt(CDate(txtFromDate.Text)) & "# And # " & Formamt(CDate(txtToDate.Text)) & "#"
Also ensure that txtFromDate and txtToDate are valid dates before attempting to run the SQL
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|