|
楼主 |
发表于 2022-2-19 17:50
|
显示全部楼层
多页控件管理列表框,生成对应控件
- Private Sub MultiPage1_Change()
- Rem 功能:关联对应工作表
- On Error GoTo Err1 '处理工作表不存在的错误
- Rem 清除列表数据
- ListView1.ColumnHeaders.Clear
- ListView1.ListItems.Clear
- Rem 获取相应记录
- xName = MultiPage1.SelectedItem.Caption '页标签
- Set Sh = Sheets(xName) '工作表
- Database = Sh.Range("A1").CurrentRegion.Value '数据记录
- Frame1.Caption = " " & xName & " "
- If UBound(Database) = 0 Then
- MsgBox "“" & xName & "表”没有任何数据!", vbCritical, "提示"
- Exit Sub
- End If
- Rem 移除旧有的控件
- If Col.Count > 0 Then
- For i = Col.Count To 1 Step -1
- Me.Frame1.Controls.Remove "Text" & i
- Me.Frame1.Controls.Remove "xLbl" & i
- Next
- Set Col = Nothing
- End If
-
- Rem 加载列表头,添加控件
- For j = 1 To UBound(Database, 2)
- ListView1.ColumnHeaders.Add , , Database(1, j)
- Call ControlAdd(j, Database(1, j))
- Next
- Frame1.ScrollHeight = (Int((Col.Count - 1) / 3)) * 36
- Me.Controls("Text1").Enabled = False
- Call cmd模糊查询_Click
- Call cmd新建_Click
- Exit Sub
- Err1:
- MsgBox Err.Description, vbExclamation, "错误"
- Err.Clear
- End Sub
复制代码 |
|