在集合中找不到请求的名称或序号的项目
Item cannot be found in the collection to the requested name or ordinal
单击数据网格中的客户端后,所有客户端信息都加载到表单的右侧,一切似乎都很好。[https://i.stack.imgur.com/Mv5ZL.png][1]
每当我点击添加付款按钮时,它都会打开付款表格。
[https://i.stack.imgur.com/DmznP.png][2]
但每当我尝试选择另一个客户端时,它都会产生运行时错误“3265”。当我单击调试按钮时,要填写的字段似乎包含了他们需要的所有信息。为什么会出现此错误? [https://i.stack.imgur.com/YuLg5.png][3]
这是我加载所有客户端的代码
Private Sub Form_Load()
Set Connect = New Class1
Set rx = New ADODB.Recordset
rx.Open "SELECT * FROM allclients ORDER by dateCreated ASC", con, 3, 3
lblLNumberRecords.Caption = Format(rx.RecordCount, "###,###,###.##")
Set DatCUSTOMERS.DataSource = rx
Me.Show
clearfields
End Sub
这是我点击客户端时的代码:
Private Sub DatCUSTOMERS_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Unload frmPaymentRecur
lblID = rx.Fields("id")
txtClientID = rx.Fields("clientCode")
txtFirstName = rx.Fields("fname")
txtLastName = rx.Fields("lname")
txtMname = rx.Fields("mname")
txtExtension = rx.Fields("extName")
txtPin = rx.Fields("pinNo")
txtDesignation = rx.Fields("designation")
txtContactNo = rx.Fields("contactNo")
txtAddress = rx.Fields("address")
txtAge = rx.Fields("Age")
txtSalary = rx.Fields("salary")
cmbAssociation.Text = rx.Fields("fieldTypeTitle")
cmbChoices.Text = rx.Fields("fieldNameTitle")
cmdEdit.Enabled = True
cmdAddLoan.Enabled = True
cmdPayments.Enabled = True
End Sub
这是我点击添加付款按钮时的代码:
Private Sub cmdPayments_Click()
Dim flagClients, dateFlag, loanFlag As Integer
flagClients = 1
dateFlag = 1
loanFlag = 1
frmPaymentRecur.lbldateFlag.Caption = dateFlag
frmPaymentRecur.lblLoanFlag.Caption = loanFlag
frmPaymentRecur.txtClientID = rx.Fields("clientCode")
frmPaymentRecur.txtFolderNo = rx.Fields("folderCode")
frmPaymentRecur.txtFullName = rx.Fields("Name")
frmPaymentRecur.txtAssociation = rx.Fields("fieldNameTitle")
frmPaymentRecur.txtSalary = rx.Fields("salary")
frmPaymentRecur.CmbSelectPaymentType.Text = "All Loans"
frmPaymentRecur.lblFlag = flagClients
If rx.State = 1 Then rx.Close
rx.Open "SELECT DISTINCT(`Loan Type`) FROM paymentview WHERE `Client Code` = '" & Trim$(txtClientID.Caption) & "'", con, 3, 3
With rx
Do While Not .EOF
frmPaymentRecur.CmbSelectPaymentType.AddItem ![Loan Type]
.MoveNext
Loop
.Close
End With
frmPaymentRecur.Show
End Sub
在您的添加付款代码中,您将在最后关闭 rx
记录集。当您尝试更新控件时,它将为空。
您还使用不同 table、paymentview
的数据填充了记录集,其中 id
可能不存在。
您应该创建一个单独的记录集来处理您的付款代码,而不是重复使用 rx
记录集。
单击数据网格中的客户端后,所有客户端信息都加载到表单的右侧,一切似乎都很好。[https://i.stack.imgur.com/Mv5ZL.png][1]
每当我点击添加付款按钮时,它都会打开付款表格。 [https://i.stack.imgur.com/DmznP.png][2]
但每当我尝试选择另一个客户端时,它都会产生运行时错误“3265”。当我单击调试按钮时,要填写的字段似乎包含了他们需要的所有信息。为什么会出现此错误? [https://i.stack.imgur.com/YuLg5.png][3]
这是我加载所有客户端的代码
Private Sub Form_Load()
Set Connect = New Class1
Set rx = New ADODB.Recordset
rx.Open "SELECT * FROM allclients ORDER by dateCreated ASC", con, 3, 3
lblLNumberRecords.Caption = Format(rx.RecordCount, "###,###,###.##")
Set DatCUSTOMERS.DataSource = rx
Me.Show
clearfields
End Sub
这是我点击客户端时的代码:
Private Sub DatCUSTOMERS_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Unload frmPaymentRecur
lblID = rx.Fields("id")
txtClientID = rx.Fields("clientCode")
txtFirstName = rx.Fields("fname")
txtLastName = rx.Fields("lname")
txtMname = rx.Fields("mname")
txtExtension = rx.Fields("extName")
txtPin = rx.Fields("pinNo")
txtDesignation = rx.Fields("designation")
txtContactNo = rx.Fields("contactNo")
txtAddress = rx.Fields("address")
txtAge = rx.Fields("Age")
txtSalary = rx.Fields("salary")
cmbAssociation.Text = rx.Fields("fieldTypeTitle")
cmbChoices.Text = rx.Fields("fieldNameTitle")
cmdEdit.Enabled = True
cmdAddLoan.Enabled = True
cmdPayments.Enabled = True
End Sub
这是我点击添加付款按钮时的代码:
Private Sub cmdPayments_Click()
Dim flagClients, dateFlag, loanFlag As Integer
flagClients = 1
dateFlag = 1
loanFlag = 1
frmPaymentRecur.lbldateFlag.Caption = dateFlag
frmPaymentRecur.lblLoanFlag.Caption = loanFlag
frmPaymentRecur.txtClientID = rx.Fields("clientCode")
frmPaymentRecur.txtFolderNo = rx.Fields("folderCode")
frmPaymentRecur.txtFullName = rx.Fields("Name")
frmPaymentRecur.txtAssociation = rx.Fields("fieldNameTitle")
frmPaymentRecur.txtSalary = rx.Fields("salary")
frmPaymentRecur.CmbSelectPaymentType.Text = "All Loans"
frmPaymentRecur.lblFlag = flagClients
If rx.State = 1 Then rx.Close
rx.Open "SELECT DISTINCT(`Loan Type`) FROM paymentview WHERE `Client Code` = '" & Trim$(txtClientID.Caption) & "'", con, 3, 3
With rx
Do While Not .EOF
frmPaymentRecur.CmbSelectPaymentType.AddItem ![Loan Type]
.MoveNext
Loop
.Close
End With
frmPaymentRecur.Show
End Sub
在您的添加付款代码中,您将在最后关闭 rx
记录集。当您尝试更新控件时,它将为空。
您还使用不同 table、paymentview
的数据填充了记录集,其中 id
可能不存在。
您应该创建一个单独的记录集来处理您的付款代码,而不是重复使用 rx
记录集。