excel - 自动数据输入表
问题描述
试图获得帮助以找出为什么我的数据表单没有正确链接到我的数据库。我对此很陌生,并尝试多次遵循教程来获得我需要的东西,但是一路走来,无论我进行什么调整,我都会遇到问题。
这是表单的样子: 在此处输入图像描述
连接到一个 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 错误本身就非常复杂,说明了Rowsource Property
. 在您的代码中,错误应该在这里:
.lstDatabase.RowSource = "Database!A2:K"
显然在 之后缺少一些东西K
,例如:
.lstDatabase.RowSource = "Database!A2:K1"
推荐阅读
- android - 应用程序“插件”扩展移动应用程序的功能
- swift - Swift getter 隐式返回表达式
- c# - 如何通过 xml 配置文件并更新每个端点 C#
- android - 如何创建三角形自定义形状android
- python - 一个 elif 语句似乎没有在它应该运行的时候运行
- python - mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)
- ios - 为什么 iOS 数据保护代表会被多次调用?
- c# - 从 .Net System.DateTime 生成 Google Protobuf 时间戳
- python - 你如何比较python中函数的输出?
- jquery - 我已经使用了此代码。但无法禁用某些文本框。那么,我怎样才能禁用某些文本框?