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

Dynamically Creating Check Boxes On A Form 1

Status
Not open for further replies.

GGleason

Technical User
Mar 22, 2001
321
US
I want to take the contents from a query and dynamically create and arrange check boxes on a form. The label for the check box will come from one of the query fields. The field has a maximum length of 8 characters. There will be as few as 10 records and as many as 100.

Is this possible? If it is possible, can someone post sample code?

TIA,
GGleason
 
It is possible to do. I have done it in my database with good results. Here is the code i used to create the labels from the data in a table/query. Just adapt it to your needs and if you have any questions, feel free to e-mail me. I have labeled all of the check boxes Option1 through whatever # you have. Also, label the checkbox labels OptionLabel1 .. etc..



Const conOptions = 10 'Change to your max # or records
Dim dbs As Database
Dim rst As Recordset
Dim intOption As Integer

Me![Option1].SetFocus
For intOption = 2 To conOptions
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption


Set dbs = CurrentDb()
strsql = "SELECT * FROM NewProducts"

Set rst = dbs.OpenRecordset(strsql)

If (rst.EOF) Then
MsgBox ("There are no Options Available for this form.")
Else
While (Not (rst.EOF))
Me("Option" & rst![Option_Number]).Visible = True
Me("OptionLabel" & rst![Option_Number]).Visible = True
Me("OptionLabel" & rst![Option_Number]).Caption = rst![Option_Text]
rst.MoveNext
Wend

End If
rst.Close
dbs.Close
 
If, as I suspect, you're trying to take field values that were choices made by the user and display all the possible choices but have a check beside only those the user selected(or some similar scenario). This can be done "dynamically" using a couple of nested queries and formatting the form to give the appearance desired. If this is the case, let me know and I'll detail the technique.
 
asenft and Jerry,

Thanks for responding.

GGleason
 
asenft,

Can you tell me where this code goes? Does it go into a module? How does the form call this? I have very little experience working with forms so any advice you can give me would be helpful.

Thanks,
GGleason
 
Jerry D.

If it would be alright, I would like to incorporate something similar to what you are saying . . .

If you have the time and are interested in listening to my dilema, please respond to chad.bixby@whiteman.af.mil

Thanks bro!
Chance~
 
GGleason-
The code goes in the onLoad event of the form you are trying to dynamically build the fields on. Right click on the upper left hand corner of the form and go to properties. Click on the event tab, and open the code builder for the onLoad event of that form. Stick it in there.

Aaron Senft
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top