By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

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

P: 1
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
Expand|Select|Wrap|Line Numbers
  1. Dim rsname1 as recordset
  2. Dim conn As Connection
  3. Set conn = New Connection
  4. conn.Open "provider=Microsoft.jet.OLEdb.4.0;Data Source=C:\Documents and Settings\admin\My Documents\medical.mdb"
  5. Set rsname1 = New Recordset
  6. rsname1.Open "select * from MASTER order by [PRODUCT NAME]", conn, adOpenDynamic, adLockPessimistic
  7.  
  8.  
  9. If Option2.Value = True Then
  10.     rsname1.Close
  11.     Set rsname = Nothing
  12.     rsname1.CursorLocation = adUseClient
  13.    rsname1.Open "select * from MASTER order by [COMPANY NAME],[PRODUCT NAME],[PRODUCT TYPE],[PRODUCT SIZE]"
  14.  
  15.    Form3.DataGrid1.DataMember = ""
  16.    Set Form3.DataGrid1.DataSource = rsname1
  17.    Form3.DataGrid1.Refresh
  18.     rsname1.Requery
  19.  
  20. ElseIf option1.Value = True Then
  21.    rsname1.Close
  22.    Set rsname1 = Nothing
  23.    rsname1.CursorLocation = adUseClient
  24.  
  25.    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, adLockPessimistic"
  26.  
  27.  
  28. Form3.DataGrid1.DataMember = ""
  29. Set Form3.DataGrid1.DataSource = rsname1
  30.    Form3.DataGrid1.Refresh
  31.     rsname1.Requery
  32. End If
  33.    End Sub

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
Sep 25 '07 #1
Share this Question
Share on Google+
1 Reply


P: 82
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
Expand|Select|Wrap|Line Numbers
  1.     Set rsname = Nothing
  2.  
rsname1.CursorLocation = 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
Expand|Select|Wrap|Line Numbers
  1. Set rsname1 = Nothing
and its good to go.
Sep 25 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.