Results 1 to 7 of 7

Thread: How to find the date range in MS Access and display in MS Flex Grid?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation 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.

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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:
    1. Sql = "Select * From <TableName> Where MyDate Between DateValue ('" & txtFromDate.Text & "') And DateValue ('" & txtToDate.Text & "')"
    2. Rs.Open Sql, Cn, adOpenDynamic, adLockOptimistic
    3. i = 1
    4. Do While Not Rs.EOF
    5.     FlexGrid.TextMatrix(i, 1) = Rs!FieldName1
    6.     FlexGrid.TextMatrix(i, 2) = Rs!FieldName2
    7.     FlexGrid.TextMatrix(i, 3) = Rs!FieldName3
    8.     ' and so on
    9.     i = i + 1
    10.     Rs.MoveNext    
    11. Loop
    12. 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.


  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation 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.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation 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.

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation 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.

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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:
    1. 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
  •  



Click Here to Expand Forum to Full Width