checkbox - Setting CheckBoxes from another userform in VBA -
i have userform contains number of checkboxes 1 100. have written simple code when submit form creates binary string represents state of 100 checkboxes, 0 false , 1 true. code here:
private sub busrulessubmit_click() dim mybinarystring string dim nm string dim c control busruleidx = 1 100 nm = "checkbox" & busruleidx set c = controls(nm) if c.value = true mybinarystring = mybinarystring & "1" else mybinarystring = mybinarystring & "0" end if next msgbox mybinarystring end sub
i want open userform form, have similar binary string, , use string set values of checkboxes true or false appropariate. having issues when setting control. code here:
private sub populatebusrules() dim c control dim mybrbinary string mybrbinary = "000000000011100000000000000000000000000000000000000000000000000000000010000000000000000000000000000" busruleidx = 1 100 nm = "businessrules.checkbox" & busruleidx set c = controls(nm) if mid(mybrbinary, buruleidx - 1, 1) = 1 c.value = true else c.value = false end if next end sub
when run above, runtime error "could not find specified object" , when going debug highlights problem code states "set c = controls(nm)" - , can see failing in first round of loop i.e. nm = "businessrules.checkbox1"
interestingly if run code "set c = controls(businessrules.checkbox1)" no such issue.
any appreciated.
thanks,
paul.
i think businessrules
giving issue. in controls collection, there no control named "businessrules.checkbox1"
, 1 named "checkbox1"
within businessrules.controls
collection. assuming there aren't other issues mentioned in comments above (like form being closed before called), should fix issue
Comments
Post a Comment