Dynamic Select box, using Radio Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone have the code to change items in a select box, depending on which
radio button has been selected by the user?

Thank you
 
Hi.

Does "select box" refer to a list box, a combo box, or labels for buttons in
an option group? If it's a list box or combo box, you would just assign a
new value to the RecordSource (and possibly the RecordSourceType -- it
depends upon your situation) for this object. For example, a combo box
called cboItems could have its list changed at run-time like this:

Me.cboItems.RowSource = "SELECT MyField FROM MyTable;"

You can use the "Before Update" event of an option group to make the desired
change (or even call a subroutine that makes the specific change that you
want). For example:

Private Sub grpSelect_BeforeUpdate(Cancel As Integer)

On Error GoTo ErrHandler

Select Case grpSelect.Value
Case 1
Me.cboItems.RowSource = "SELECT MyField FROM MyTable;"
Case 2
Me.cboItems.RowSource = "SELECT YourField FROM YourTable;"
End Select

Exit Sub

ErrHandler:

MsgBox "Error in grpSelect_BeforeUpdate( ) in " & vbCrLf & Me.Name & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description

End Sub ' grpSelect_BeforeUpdate( )

.. . . where grpSelect is the name of the option group containing two radio
buttons.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts, so that all
may benefit by filtering on "Answered questions" and quickly finding the
right answers to similar questions. Remember that the best answers are often
given to those who have a history of rewarding the contributors who have
taken the time to answer questions correctly.
 
Back
Top