Как переписать эту подпрограмму с циклом для i = 1 до 12 и в то время как 'txt_Case_Number (i) .Text' имеет значение? - PullRequest
0 голосов
/ 11 января 2019

Я создал поисковую форму пользователя, которая должна показывать записи при поиске номера дела, в котором может быть частично дублирующаяся информация. Затем я изменяю эту запись и обновляю лист новой информацией. Примерно так я и пытаюсь сделать:

While i = 1 to 12
    .Cells(RowFound(i), "A") = txt_Case_Number(i).Text
    .Cells(RowFound(i), "B") = cmboCase_Status(i).Text

Ниже приведено то, что у меня есть, и я хочу сделать это, как показано выше.

Private Sub cmdMakeEdit1_Click()        
    With Sheets("Sheet1")
        .Cells(RowFound1, "A") = txt_Case_Number1.Text
        .Cells(RowFound1, "B") = cmboCase_Status1.Text
        .Cells(RowFound1, "C") = txtDate_of_Seizure1.Text
        .Cells(RowFound1, "D") = txtSeizure_Type1.Text
        .Cells(RowFound1, "L") = TxtCurr1.Text
        .Cells(RowFound1, "N") = TxtCurr_Dep1.Text
        .Cells(RowFound1, "S") = txtPDH_CourtDate1.Text
        .Cells(RowFound1, "U") = txtDays_PDH_Courtdate1.Text
        .Cells(RowFound1, "V") = txtPC_Received1.Text
        .Cells(RowFound1, "W") = txtDays_464_Filing1.Text
        .Cells(RowFound1, "Y") = txt464_Filed1.Text
        .Cells(RowFound1, "Z") = txtDays_Article36_Filing1.Text
        .Cells(RowFound1, "AA") = txtArticle_36_Due1.Text
        .Cells(RowFound1, "AB") = txtArticle_36_Filed1.Text
        .Cells(RowFound1, "AC") = txtDeclaration_Letter1.Text
        .Cells(RowFound1, "AE") = txtCurr_Sent_ISP1.Text
        .Cells(RowFound1, "AF") = txtAmount_Sent1.Text
        .Cells(RowFound1, "AG") = txtYear1.Text
        .Cells(RowFound1, "AH") = cmbo_Make1.Text
        .Cells(RowFound1, "AI") = cmbo_Model1.Text
        .Cells(RowFound1, "AJ") = cmbo_Color1.Text
        .Cells(RowFound1, "AK") = txtPlate1.Text
        .Cells(RowFound1, "AL") = txtVIN1.Text
        .Cells(RowFound1, "AM") = txtLEADS1.Text
        .Cells(RowFound1, "AN") = txtOwners_Name1.Text
        .Cells(RowFound1, "AQ") = txtLien1.Text
        .Cells(RowFound1, "AT") = cmbLocation1.Text
        .Cells(RowFound1, "AU") = txtFull_Name1.Text
        .Cells(RowFound1, "AV") = txtItem_Desc1.Text
        .Cells(RowFound1, "AW") = txtItem_Model1.Text
        .Cells(RowFound1, "AX") = txtItem_Serial1.Text
        .Cells(RowFound1, "AY") = txtOther_Info1.Text
        .Cells(RowFound1, "AZ") = txtItem_PickedUP1.Text
        .Cells(RowFound1, "BA") = txt_Search1_Type.Text

Ответы [ 2 ]

0 голосов
/ 11 января 2019

Один из единственных способов просмотра элементов управления формой - инициализация элемента управления и его использование в цикле For-Each. Затем вы можете проверить имя или тип элемента управления в операторе If, например

Dim ctl As Control

For Each ctl in Me.Controls '<-assuming your button is on the form the rest of the controls are
    If TypeName(ctl) = "TextBox" or TypeName(ctl) = "ComboBox" Then
        'Do Stuff'
    End If
Next ctl
0 голосов
/ 11 января 2019

Вы можете захотеть:

i = 1
While (txt_Case_Number(i).Text <> "" And i <= 12)
    '...
    i = i + 1
Wend
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...