Results 1 to 8 of 8

Thread: queries question doing between date

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    kentucky
    Posts
    5
    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.



  2. #2
    Addicted Member JasonGS's Avatar
    Join Date
    May 2000
    Location
    California
    Posts
    155
    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 & "#"

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    kentucky
    Posts
    5
    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?

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    kentucky
    Posts
    5
    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


  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    kentucky
    Posts
    5
    little more help please

  7. #7
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    kentucky
    Posts
    5
    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width