display data in datagrid using adodc through code in depending on query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DIPPU
    New Member
    • Sep 2007
    • 1

    #1

    display data in datagrid using adodc through code in depending on query

    hello sir, m using 4 combo boxes,2 option buttons,button. wen option named single type is clicked data grid must show the data i selected in combo boxes,wen all type option button is clicked then grid shows the all rows in access table.but both option buttons shows all rows in grid the code i have used is
    [CODE=vb]Dim rsname1 as recordset
    Dim conn As Connection
    Set conn = New Connection
    conn.Open "provider=Micro soft.jet.OLEdb. 4.0;Data Source=C:\Docum ents and Settings\admin\ My Documents\medic al.mdb"
    Set rsname1 = New Recordset
    rsname1.Open "select * from MASTER order by [PRODUCT NAME]", conn, adOpenDynamic, adLockPessimist ic


    If Option2.Value = True Then
    rsname1.Close
    Set rsname = Nothing
    rsname1.CursorL ocation = adUseClient
    rsname1.Open "select * from MASTER order by [COMPANY NAME],[PRODUCT NAME],[PRODUCT TYPE],[PRODUCT SIZE]"

    Form3.DataGrid1 .DataMember = ""
    Set Form3.DataGrid1 .DataSource = rsname1
    Form3.DataGrid1 .Refresh
    rsname1.Requery

    ElseIf option1.Value = True Then
    rsname1.Close
    Set rsname1 = Nothing
    rsname1.CursorL ocation = adUseClient

    rsname1.Open "select * from MASTER where [COMPANY NAME]='" & Combo1.Text & "' and [PRODUCT NAME]='" & Combo2.Text & "' and [PRODUCT TYPE]='" & Combo3.Text & "' and [PRODUCT SIZE]='" & Combo4.Text & "', conn, adOpenDynamic, adLockPessimist ic"


    Form3.DataGrid1 .DataMember = ""
    Set Form3.DataGrid1 .DataSource = rsname1
    Form3.DataGrid1 .Refresh
    rsname1.Requery
    End If
    End Sub[/CODE]


    till now u might understood the problem m facing.actually problem is with option 2 ie single type.after clicking the command button values must appear in grid.
    the error msg m getting is object r variable not decalred.please help me sir
    thank u
    Last edited by debasisdas; Sep 25 '07, 12:27 PM. Reason: Formatted using code tags.
  • fplesco
    New Member
    • Jul 2007
    • 82

    #2
    Originally posted by DIPPU
    till now u might understood the problem m facing.actually problem is with option 2 ie single type.after clicking the command button values must appear in grid.
    the error msg m getting is object r variable not decalred.please help me sir
    thank u
    Hi -

    Your problem is rsname. It was declared as rsname1. See font emphasized below.

    If Option2.Value = True Then
    rsname1.Close
    Code:
        Set rsname = Nothing
    rsname1.CursorL ocation = adUseClient
    rsname1.Open "select * from MASTER order by [COMPANY NAME],[PRODUCT NAME],[PRODUCT TYPE],[PRODUCT SIZE]"

    Form3.DataGrid1 .DataMember = ""
    Set Form3.DataGrid1 .DataSource = rsname1
    Form3.DataGrid1 .Refresh
    rsname1.Requery

    Just change that to
    Code:
    Set rsname1 = Nothing
    and its good to go.
    Last edited by debasisdas; Sep 25 '07, 12:31 PM. Reason: Removed too much quote.

    Comment

    Working...