vba - Error Checking Option Boxes -


i'm trying build in error checking 2 option boxes have:

projectoptionbox implementoptionbox 

this current code have right error checking couple of other things, unsure kind of code necessary option boxes:

function checkinputs() boolean     if not checkcontrol(me.nametextbox, "please enter name") exit function     if not checkcontrol(me.projecttextbox, "please enter project name") exit function     if not checkcontrol(me.initiativecombobox, "please select initiative") exit function     if not checkcontrol(me.audiencecombobox, "please select audience") exit function     if not checkcontrol(me.impactcombobox, "please select impact type") exit function     if not checkcontrol(me.hourstextbox, "please enter amount of monthly hours") exit function     if not checkcontrol(me.peopletextbox, "please enter amount of people on project") exit function     if not checkcontrol(me.lengthlistbox, "") if not checkcontrol(me.lengthlistbox2, "please select project length") exit function      checkinputs = true end function  private function countselectedlistboxitems(lb msforms.listbox) long     dim long     lb         = 0 .listcount - 1             if .selected(i) countselectedlistboxitems = countselectedlistboxitems + 1         next     end end function  function checkcontrol(ctrl msforms.control, errmsg string) boolean     select case typename(ctrl)         case "textbox"             checkcontrol = trim(ctrl.value) <> ""         case "combobox"             checkcontrol = ctrl.listindex <> -1         case "listbox"             checkcontrol = countselectedlistboxitems(ctrl) > 0 '        case else     end select     if errmsg = "" exit function     if checkcontrol exit function     ctrl.setfocus     msgbox errmsg end function 

from gathered post, sounds want develop method of confirming optionbutton within group has been selected. (not looking application error per se, rather violation of business logic).

this bit more complicated checks on other controls because other controls standalone. there 2 options. (1) since optionbutton control doesn't support null state, can set default option on form's initialization. then, irrespective of user does, 1 of options selected.

the other option use groupname property of optionbuttons put buttons group. (when optionbuttons in group, ensures 1 of them selected). next, can loop through of controls looking optionbuttons of same groupname, check if @ least 1 of them selected. helper function such 1 below should trick:

private function optionboxgrouphasaselection(inputcontrol msforms.control) boolean     dim ctrl msforms.control     dim sgroup string     dim boutput boolean      if typename(inputcontrol) <> "optionbutton"         optionboxgrouphasaselection = false         exit function     end if      if inputcontrol.value = true         optionboxgrouphasaselection = true         exit function     end if      sgroup = inputcontrol.groupname     boutput = false      each ctrl in me.controls         if typename(ctrl) = "optionbutton"             if ctrl.groupname = sgroup                 if ctrl.value = true                     boutput = true                     exit                 end if             end if         end if     next ctrl      optionboxgrouphasaselection = boutput end function 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -