Click to See Complete Forum and Search --> : queries question doing between date
Dave8366
Jun 22nd, 2000, 08:26 AM
Im new to Vb so please make answer easy as possible
I have a Access database call Test
a table Call READINGS
Field - ReadingID
Field - LastName
Field - Date
Field - Reading
Vb 6
I will have a form which on it will have:
Flexgrid for data to be display in
a command button to run query
either
2 text boxes begdate and enddate to query
maybe DTpicker boxes.
I have looked HIGH and Low for some type of example of this. Where I can see how its done.
JasonGS
Jun 22nd, 2000, 08:30 AM
Your recordset command text to your database would be
' Raw SQL Statement
SELECT * FROM table WHERE datefield BETWEEN #date1# AND #date2#
' VB Usage
Object.CommandText = "SELECT * FROM table WHERE datefield BETWEEN #" & begdate.Text & "# AND #" & enddate.Text & "#"
Dave8366
Jun 22nd, 2000, 09:03 AM
Im not sure where to place the statments.
Do I need to build a query under VISDATA?
Then how would I get the data into the flexgrid?
Chris
Jun 22nd, 2000, 12:27 PM
I just work out some code for you and hope you understand what I have wrote. Basically, I just use the following control:
MSHFlexGrid x1
ADO Data Control x1
DateTime Picker x2
Command Button x1
You can see I didn't use the MSFlexGrid here, this because the MSFlexGrid only can interact with DAO Data Control and not ADO Data Control. If you persist to use MSFlexGrid, then you only can use the DAO Data Control.
Option Explicit
Private Sub Command1_Click()
Dim MySQL As String
'Check for valid Start date and End date
If DateValue(DTPicker1.Value) > DateValue(DTPicker2.Value) Then
MsgBox "invalid end data!", vbExclamation + vbOKOnly
Else
MySQL = "SELECT * FROM READINGS WHERE Last_Date BETWEEN #" & DTPicker1.Value & " 12:00:00 AM# AND #" & DTPicker2.Value & " 11:59:59 PM# ORDER BY ReadingID ASC;"
Adodc1.RecordSource = MySQL
Adodc1.Refresh
End If
End Sub
Private Sub Form_Load()
'Create Connection
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\Test.mdb"
Adodc1.RecordSource = "SELECT * FROM READINGS ORDER BY ReadingID ASC;"
Adodc1.Refresh
'Pull data into MSHFlexGrid Control
Set MSHFlexGrid1.DataSource = Adodc1
MSHFlexGrid1.Refresh
'Reset the DTPicker
DTPicker1.Value = Format(Now, "dd/mm/yyyy")
DTPicker2.Value = Format(Now, "dd/mm/yyyy")
End Sub
Dave8366
Jun 23rd, 2000, 09:20 AM
Getting error
No Value Given for one or more Required Parameters
Method 'refresh' of object'IADODC' Failed
'Pull data into MSHFlexGrid Control
Debug points to this line MSHFlexGrid1.Refresh
Dave8366
Jun 26th, 2000, 09:01 AM
little more help please
Chris
Jun 26th, 2000, 01:45 PM
Hi Dave8366, Which part that you encounter error? is the mand1_click() or form_load() events?
if you don't mind, can you can post your code.
Dave8366
Jun 27th, 2000, 08:44 AM
Chris,
I used the code you posted.
The error was:
No Value Given for one or more Required Parameters
Method 'refresh' of object'IADODC' Failed
The debug was pionting in the form part of code
Private Sub Form_Load()
Adodc1.Refresh is the line failing
If you want I can Email form to you let you see it.
jmenees@ka.net
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.