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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to bound optionbutton to the database?

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
I would like to use option buttons to ask users to make their choice. But I know how to bind textbox control to database, but do not know how to bind optionbuttons? Need to write a function or ....?

Haijun
 
Put the option buttons in a fram, the option buttons should be indexed within the frame. i.e. they should all have the same name. Then bind the group to the DB. Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
Could you give me a example?

Thanks

Haijun
 
That depends. Are you binding everything to a data control. i.e. do you have one of theose Data controls set to the DB, then set to the table. Then each control set to the data control and column name. Or are you using something like DAO or ADO. Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
I do need to bind every control to the a backend database table, I am using ADO right now. The binding to textbox control is good, but optionbutton???

Haijun
 
I think this should work...

Pu the first option button on the form. Bind it to the DB column. Then copy it, when it asks if you want to index the controls say yes. That should work. Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
How to bind the button to the db column? There is no datasource, or datafield properties to configure.

Haijun
 
Check the value of the field in the database and set the corresponding option button's value to selected.

Good luck
 
Guru but what happens if you have 1 column and 6 buttons....

If you can't bind it your going to have to do this in Code.

When the record is added or changed, you going to have to find which option button is selected and set the value to the DB. Let's say you have many option buttons and only 1 can be on at a time.

For 1 = 0 to Ubound(optButton())
If optButton(i) = vbChecked then
rs.Fields("ColumnName") = i
end if
Next i

Then to show the value you do this.

optButton(val(rs.Fields("ColumnName")) = vbChecked Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top