goddess_spanky
July 30th, 2001, 04:50 PM
I am trying to add radio buttons dynamically at run-time, but am having a couple of problems.
I want to create two option groups. the first is created when the form is loaded. the second group is created when an option from the first group is selected. this works until i select a different option from the first group. the second group won't re-create the new options. Make sense? Any ideas?
Also, I want to be able to set the second group's index property value to a field key in my database (like 40 or 85 depending on the record) when I do this, I get an error for the first option because it doesn't start with 1, when i try to assign a value equal to i - 1 it says the property is read-only. am i doing something wrong?
Any help is greatly appreciated!!
Thanks!
'//this sub works fine, i just included it as a reference for the next sub which is where i am having the problems
private Sub Form_Load()
Dim i as Integer
Dim conn as new ADODB.Connection
Dim rs as new ADODB.Recordset
Dim sql as string
Dim foxpro as string
foxpro = "DB_Tracking"
sql = "SELECT * FROM tbl_supcategory ORDER BY cat_key"
conn.Open foxpro
rs.Open sql, conn, , adLockReadOnly
i = rs.Fields("cat_key")
rs.MoveFirst
While rs.EOF = false
Load optCategory(i)
optCategory(i).Caption = rs.Fields("Category")
optCategory(i).Top = optCategory(i - 1).Top + optCategory(i - 1).Height
optCategory(i).Left = optCategory(i - 1).Left
optCategory(i).Value = false
optCategory(i).Visible = true
i = i + 1
rs.MoveNext
Wend
fraCategory.Height = optCategory(i - 1).Top + optCategory(i - 1).Height + 75
optCategory(0).Visible = false
rs.Close
conn.Close
set rs = nothing
set conn = nothing
End Sub
'//this is where I am having the problems
private Sub optCategory_Click(Index as Integer)
Dim i as Integer
Dim conn as new ADODB.Connection
Dim rs as new ADODB.Recordset
Dim sql as string
Dim foxpro as string
Dim cat_key as string
cat_key = Index
foxpro = "DB_Tracking"
sql = "SELECT * FROM tbl_sup_subcat WHERE cat_key = " & Chr(10) & cat_key & Chr(10) & " ORDER BY sub_key"
conn.Open foxpro
rs.Open sql, conn, , adLockReadOnly
'//if I set i equal to the key in the database, i get error described below
i = rs.Fields("sub_key")
'i = 1
rs.MoveFirst
optSubCategory(0).Index = i - 1
While rs.EOF = false
Load optSubCategory(i)
optSubCategory(i).Caption = rs.Fields("SubCategory")
'//this next line is where i get the error "control array element 'item' doesn't exist"
optSubCategory(i).Top = optSubCategory(i - 1).Top + optSubCategory(i - 1).Height
optSubCategory(i).Left = optSubCategory(i - 1).Left
optSubCategory(i).Value = false
optSubCategory(i).Visible = true
i = i + 1
rs.MoveNext
Wend
optSubCategory(0).Visible = false
rs.Close
conn.Close
set rs = nothing
set conn = nothing
Text1.Text = Index
End Sub
Thanks~
~goddess
goddess_spanky@hotmail.com
I want to create two option groups. the first is created when the form is loaded. the second group is created when an option from the first group is selected. this works until i select a different option from the first group. the second group won't re-create the new options. Make sense? Any ideas?
Also, I want to be able to set the second group's index property value to a field key in my database (like 40 or 85 depending on the record) when I do this, I get an error for the first option because it doesn't start with 1, when i try to assign a value equal to i - 1 it says the property is read-only. am i doing something wrong?
Any help is greatly appreciated!!
Thanks!
'//this sub works fine, i just included it as a reference for the next sub which is where i am having the problems
private Sub Form_Load()
Dim i as Integer
Dim conn as new ADODB.Connection
Dim rs as new ADODB.Recordset
Dim sql as string
Dim foxpro as string
foxpro = "DB_Tracking"
sql = "SELECT * FROM tbl_supcategory ORDER BY cat_key"
conn.Open foxpro
rs.Open sql, conn, , adLockReadOnly
i = rs.Fields("cat_key")
rs.MoveFirst
While rs.EOF = false
Load optCategory(i)
optCategory(i).Caption = rs.Fields("Category")
optCategory(i).Top = optCategory(i - 1).Top + optCategory(i - 1).Height
optCategory(i).Left = optCategory(i - 1).Left
optCategory(i).Value = false
optCategory(i).Visible = true
i = i + 1
rs.MoveNext
Wend
fraCategory.Height = optCategory(i - 1).Top + optCategory(i - 1).Height + 75
optCategory(0).Visible = false
rs.Close
conn.Close
set rs = nothing
set conn = nothing
End Sub
'//this is where I am having the problems
private Sub optCategory_Click(Index as Integer)
Dim i as Integer
Dim conn as new ADODB.Connection
Dim rs as new ADODB.Recordset
Dim sql as string
Dim foxpro as string
Dim cat_key as string
cat_key = Index
foxpro = "DB_Tracking"
sql = "SELECT * FROM tbl_sup_subcat WHERE cat_key = " & Chr(10) & cat_key & Chr(10) & " ORDER BY sub_key"
conn.Open foxpro
rs.Open sql, conn, , adLockReadOnly
'//if I set i equal to the key in the database, i get error described below
i = rs.Fields("sub_key")
'i = 1
rs.MoveFirst
optSubCategory(0).Index = i - 1
While rs.EOF = false
Load optSubCategory(i)
optSubCategory(i).Caption = rs.Fields("SubCategory")
'//this next line is where i get the error "control array element 'item' doesn't exist"
optSubCategory(i).Top = optSubCategory(i - 1).Top + optSubCategory(i - 1).Height
optSubCategory(i).Left = optSubCategory(i - 1).Left
optSubCategory(i).Value = false
optSubCategory(i).Visible = true
i = i + 1
rs.MoveNext
Wend
optSubCategory(0).Visible = false
rs.Close
conn.Close
set rs = nothing
set conn = nothing
Text1.Text = Index
End Sub
Thanks~
~goddess
goddess_spanky@hotmail.com