Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Buttons Changing Query Dynamically

Status
Not open for further replies.

SAXMAN99

Technical User
Jun 10, 2003
11
CA
I have a question:
I have a form, combo box looks up a value in a field, then a then the form refreshes and the query(in a subform) also refreshes to make the data showing reflect the selection in the combo box. my prob is that, i need to have two groups of three radio buttons where for example i check the first button(Blue) i would see only the blue items in my query, but if i chose the second(red) i would see the red ones, but if i chose all(third button).i would see both the red and the blue items in my query, but showing in my subform.
what i thought i should do is tell my query to look up the values in the group, but im not sure how to do that. can anyone help?
 

I made this sample to help someone having problem, binding DataSet to TextBox and changing the selection string dynamically on click of RadioButton. Might help you someway

Private Sub onRadioButtonCheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
Dim strSQL As String

'Clear DataBindings for the TextBox.
TextBox1.DataBindings.Clear()
TextBox2.DataBindings.Clear()
TextBox3.DataBindings.Clear()

If RadioButton1.Checked = True Then
'Build the SQL string.
strSQL = "SELECT ProspectID, Surname, Phone " & _
"FROM Prospects"
Else
'Build the SQL string.
If RadioButton2.Checked = True Then
strSQL = "SELECT CustomerID, CompanyName, ContactName " & _
"FROM Customers"
End If
End If

'Call subroutine BindTextBox().
BindTextBox(strSQL)
End Sub


Private Sub BindTextBox(ByVal strSQL As String)
Dim strConn As String
Dim Conn As OleDbConnection

Dim objDA As OleDbDataAdapter
Dim objDS As New DataSet()

Try
'Build the Connection strings.
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Temp\ProspectDB.mdb"

'Pass the Connection string to OleDbConnection object.
Conn = New OleDbConnection(strConn)

'Initialize the OleDbDataAdapter with SQL and Connection string,
'and then use the OleDbAdapter to fill the DataSet with data.
objDA = New OleDbDataAdapter(strSQL, Conn)
objDA.Fill(objDS)

'Bind the TextBox to respective fields.
TextBox1.DataBindings.Add(New Binding("Text", objDS, objDS.Tables(0).ToString & "." & objDS.Tables(0).Columns(0).ToString))

TextBox2.DataBindings.Add(New Binding("Text", objDS, objDS.Tables(0).ToString & "." & objDS.Tables(0).Columns(1).ToString))

TextBox3.DataBindings.Add(New Binding("Text", objDS, objDS.Tables(0).ToString & "." & objDS.Tables(0).Columns(2).ToString))

Catch Excep As System.Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End Sub


Email: pankajmsm@yahoo.com
 
This is good, but not exactly what i need. i need to be able to change the query when i click on a radio button(the form refreshes after the click along with the query).
eg.
Select drop down menu
Select radio1, something like query.field=radio.caption
refresh everything
Now: the caption of the radio button is the exact text of the field value, and i need to requery/refresh according to the radio button selection
i also have one radio(radio3) button that can lookup 'all'
where when radio 3 is clicked, all the values of that field are selected and i should see all my records.
im using access 2000 with sp3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top