Private Sub Command51_Click()
Me.子窗体.Requery
Me.Text22 = DCount("21", "考卷", "考卷.[21]=-1")
Me.Text34 = DCount("22", "考卷", "考卷.[22]=-1")
Me.Text24 = DCount("23", "考卷", "考卷.[23]=-1")
Me.Text26 = DCount("24", "考卷", "考卷.[24]=-1")
Me.Text28 = DCount("25", "考卷", "考卷.[25]=-1")
Me.Text30 = DCount("26", "考卷", "考卷.[26]=-1")
Me.Text32 = DCount("27", "考卷", "考卷.[27]=-1")
Me.Text36 = DCount("28", "考卷", "考卷.[28]=-1")
Me.Text38 = DCount("29", "考卷", "考卷.[29]=-1")
Me.Text40 = DCount("30", "考卷", "考卷.[30]=-1")
Me.Text52 = DCount("无", "考卷", "考卷.[总]=-1")
Me.Text84 = DCount("无", "考卷", "考卷.[无]=-1")
'--------------------------以上为你原有的---------------------------
Dim i, arr, mVal, mCtl As Control, cp
arr = Split("22,34,24,26,28,30,32,36,38,40,84", ",") '设置数组,只是为了方便循环
mVal = Text22 '任意选定一个文本框为起点值
Set mCtl = Me.Text22 '任意选定一个文本框为起点控件
For i = 0 To UBound(arr)
If Me.Controls("Text" & arr(i)) > mVal Then '如果循环中的文本框值大于变量mVal的值
mVal = Me.Controls("Text" & arr(i)) '把循环中的文本框值赋给变量mVal
Set mCtl = Me.Controls("Text" & arr(i)) '把循环中的文本框控件赋给变量mCtl
End If
Next i
cp = mCtl.Controls(0).Caption '获得值最大的文本框控件的关联标签的caption,即该标签显示的文字
Text87 = cp '把标签文字赋给文本框
End Sub