VB 6.0 - How to search a date range in Ms Access?
Asked By Eric Kong on 11-Apr-06 11:34 PM
Ho do i search a date range for example i want to search the date from 01/01/2026 to 01/02/2026 and all the records from these date range will be display in Ms Flexi Grid. Can someone help me with this??
Thanks.
use Between
Asked By mv ark on 11-Apr-06 11:52 PM
in your SELECT query. For ex
SELECT *
FROM Categories
WHERE (((Orders.ShippedDate) Between #1/1/1997# And #12/31/1997#))
Thanks alot
Asked By Eric Kong on 11-Apr-06 11:59 PM
Thanks alot i will try this but how do i display it in MS Flexi Grid?
hi
Asked By Rupali Randhave Kolhe on 12-Apr-06 12:10 AM
take recordset ,like rs
cnn is connection to dbase
set rs=cnn.execute("SELECT *
FROM Categories
WHERE (((Orders.ShippedDate) Between #1/1/1997# And #12/31/1997#))")
while rs.eof=false
msflexgrid.additem("rs.fields(0)")
rs.movenext
wend
try this way ,
Add field which u want
How do i declare this?
Asked By Eric Kong on 12-Apr-06 02:24 AM
cnn is connection to dbase
i'm getting an error on this
Private Sub Form_Load()
Dim rs As Recordset
Set rs = cnn.Execute("SELECT * From Kdata WHERE (((Tarikh) Between #11/01/2006# And #11/04/2006#))")
While rs.EOF = False
MSHFlexGrid1.AddItem ("rs.fields(0)")
rs.MoveNext
Wend
End Sub
use ur connection
Asked By Rupali Randhave Kolhe on 12-Apr-06 02:40 AM
hi
i just give cnn for example.
use your connection to your database,
suppose u use conn then use conn instead of cnn.
ok
U mean this?
Asked By Eric Kong on 12-Apr-06 03:06 AM
u mean cnn is the path to the database? Sorry i'm new to VB. Can u give me an example? Thanks alot
try this one
Asked By Paul Moulic Jr. on 15-Apr-06 08:07 AM
OPen your Vbasic 6.0
Create the following..
1. 2 textboxes namely(text1 and text2)
2. 1 Msflexgrid
3. 1 Adodc1
4. 1 Command Button namely(command1)
5. create a database file in drive c:\ filename is db5.mdb or anyting u want
add one table name as table1 with one field name as regdate and the type is date
6. input a date records as you want example(01/03/2026 to 31/03/2026)
7. cut and paste dis source code
Private Sub Command1_Click()
Dim x As Integer
Formatview
Adodc1.RecordSource = "Select * from table1 where regdate >= datevalue('" & Text1 & "') and regdate <= datevalue('" & Text2 & "')"
Adodc1.Refresh
For x = 1 To Adodc1.Recordset.RecordCount
MSFlexGrid1.TextMatrix(x, 0) = Adodc1.Recordset.Fields("regdate")
MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
Adodc1.Recordset.MoveNext
Next x
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=c:\db5.mdb; Persist Security Info = False"
Adodc1.RecordSource = "Select * from table1"
Adodc1.Refresh
Formatview
End Sub
Sub Formatview()
MSFlexGrid1.Rows = 2
With MSFlexGrid1
.FormatString = "" & "DATE REQUIRED " & "|" & "MAINSTREET " & "|" & " SUBSTREET " & "|" & "HOUSENO" & "|" & "REQUESTERS NAME " & "|" & "CONTACT NO" & "|" & "SERVICES "
End With
End Sub
8. By running the program.. you should input a date values in text1 and text2 to query a date..
9. if any error exist.. juz check your objects and the values.. happy coding..