-
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.
-
Your recordset command text to your database would be
Code:
' 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 & "#"
-
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?
-
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.
Code:
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
-
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
-
-
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.
-
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.
[email protected]