【发布时间】:2020-09-09 18:55:29
【问题描述】:
试图获得帮助以找出为什么我的数据表单没有正确链接到我的数据库。我对此很陌生,并尝试多次遵循教程来获得我需要的东西,但一路走来,无论我调整什么,我都会遇到问题。
表单如下所示: enter image description here
连接到一个 12 列的 Excel 数据库。工作簿中只有 2 张工作表(主页和数据库) 不断收到以下错误:
- 运行时错误“380”“无法设置 RowSource 属性。无效的属性值。” “数据库”区域中应该有一个表单的迷你预览,但它没有显示出来。
这是我的代码:
Option Explicit
Sub Reset()
Dim iRow As Long
iRow = [Counta(Database!A:A)] 'identifies the last row
With frmForm
.txtID.Value = " "
.txtName.Value = " "
.txtCostc.Value = " "
.txtDept.Value = " "
.txtPay.Value = " "
.txtSdate.Value = " "
.txtSuper.Value = " "
.optCWS.Value = False
.optFWS.Value = False
.lstDatabase.ColumnCount = 12
.lstDatabase.ColumnHeads = True
.lstDatabase.ColumnWidths = "30,60,75,40,60,45,55,60,60,60,60"
If iRow > 1 Then
.lstDatabase.RowSource = "Database!A2:K" & iRow
Else
.lstDatabase.RowSource = "Database!A2:K"
End If
End With
End Sub
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A] + 1
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2) = frmForm.txtID.Value
.Cells(iRow, 3) = frmForm.txtName.Value
.Cells(iRow, 4) = frmForm.txtSuper.Value
.Cells(iRow, 5) = frmForm.txtDept.Value
.Cells(iRow, 6) = IIf(frmForm.optFWS.Value, "S09996", "S09992")
.Cells(iRow, 7) = IIf(frmForm.optCWS.Value, "S09992", "S09996")
.Cells(iRow, 8) = frmForm.txtCostc.Value
.Cells(iRow, 9) = frmForm.txtSdate.Value
.Cells(iRow, 10) = frmForm.txtPay.Value
.Cells(iRow, 11) = Application.UserName
.Cells(iRow, 12) = [Text(Now(), "DD-MM-YYY HH:MM:SS")]
End With
End Sub
Sub Show_Form()
frmForm.Show
End Sub
调试器不断将我带到 显示表单 部分:
有人知道我做错了什么吗?
【问题讨论】:
-
将您的 VBA 错误选项设置为“Break in class module”,您就会看到问题出在哪里。
标签: excel vba forms data-entry