Discussion Locked

Inserting opt button values in SQL stmt

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How do I insert values from a option button (Depending which the user selects eg Y or N) into SQL statement?

Thanks a lot in advance

5 replies

by sl-campbell

Assumming the option buttons in question are all on the same container:

1. You either need to make a loop to find out with option button was selected and assign the index to a variable:

Private m_iOptIndex As Integer

Private Sub GetOptionSelected()
Dim opt As OptionButton

For Each opt in optChoices

If optChoices.Value then
m_iOptIndex = optChoices.Index
Exit For
End If

Next opt
End Sub

OR on the Click event assign a form level variable to the index value:

Private m_iOptIndex As Integer
Private Sub optChoices_Click(Index As Integer)
m_iOptIndex = Index
End Sub

2. If you know that, for instance, option button #2 has been selected and the index is assigned to a variable, (m_iOptIndex) then you can use this in a SELECT statement, (assuming that a field exists which holds the option index to be used):

"SELECT * FROM myTable WHERE fldMyOptions=" & m_iOptIndex

This discussion is closed to new replies.