【问题标题】:Automated Data Entry Form自动数据输入表
【发布时间】:2020-09-09 18:55:29
【问题描述】:

试图获得帮助以找出为什么我的数据表单没有正确链接到我的数据库。我对此很陌生,并尝试多次遵循教程来获得我需要的东西,但一路走来,无论我调整什么,我都会遇到问题。

表单如下所示: enter image description here

连接到一个 12 列的 Excel 数据库。工作簿中只有 2 张工作表(主页和数据库) 不断收到以下错误:

  1. 运行时错误“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


【解决方案1】:

VBA 错误本身就很复杂,说的是Rowsource Property。在您的代码中,错误应该在这里:

.lstDatabase.RowSource = "Database!A2:K"

显然K后面少了一些东西,例如:

.lstDatabase.RowSource = "Database!A2:K1"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 2011-03-20
    • 2017-11-22
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    相关资源
    最近更新 更多