How to fetch value from multiple combobox in a form ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny6685
    New Member
    • Dec 2014
    • 66

    How to fetch value from multiple combobox in a form ?

    I have a form with multiple combo box created during form load, each combo box will have a name starts with "CbErrPM" and series of number.

    Say for example if I have to show 3 combo box, my form will be loaded with three combo box with name as CbErrPM1, CbErrPM2 and CbErrPM3.

    I am not sure whether all combobox will be present in the form always, sometimes it will be sometimes it will not. But I need value of combobox whenever present and need the value of combobox. Please advise How to proceed.

    I tried below but nothing working, please advise how to proceed.


    Code:
    For k = 1 To Errs
    Set FN = Form_frmQCFeedbackCorrection.Controls("CbErrPM" & k)
    If FN.Name = "CbErrPM" & k Then
    If Forms_frmQCFeedbackCorrection.( & FN & ).Value = "" Then
    Code:
    If Forms("frmQCFeedbackCorrection").Controls(FN).Value = "" Then
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3664

    #2
    Johny,

    I think you may be on the right track, to a certain degree. However, if you know that there will always be only three Errs (or however many), you may simply create your combo boxes and name them CbErrPM1, CbErrPM2 and CbErrPM3.

    You then make the combo boxes invisible, but make certain ones visible:

    Code:
    For k = 1 to 3 (or however many Errs there could be)
        Me("CbErrPM" & k).Visible = False
        Me("CbErrPM" & k).Visible = (Errs >= k)
    Next k
    Then, to check the values, you would cycle through the actual number of Errs:

    Code:
    For k = 1 to Errs
        Me("txtValue" & k) = Me("CbErrPM" & k)
    Next k
    This will also prevent you from trying to find the value of an invisible combo box, which could cause problems.

    Hope this hepps!

    Comment

    • johny6685
      New Member
      • Dec 2014
      • 66

      #3
      I have around 36 possibilities of getting combo box, and the order may vary, which is why i am creating through code.

      I have somehow managed to get the data in the initial stage to verify whether the combo box is updated or not, but now I want to update the values in table.

      I used the below code but it is updating only the blank data. Do I need to mention the complete form name. If yes, please advise how to proceed with this code.


      Code:
      UpdtblEC = "UPDATE tblErrorCorrection SET tblErrorCorrection.[" & ErrPM & "] = CbErrPM" & X & " AND tblErrorCorrection.[CStatus] = 'Correction Completed' WHERE " & whr & ""

      Comment

      Working...