【发布时间】:2021-12-05 18:35:10
【问题描述】:
@cdp1802 这是我尝试过的 哪个是错误的
我添加了其他部门并尝试查看将其他控件的值存储在数组中的可能性....显然不是最好的方法
主要是用户需要在指定数量之前输入服务,然后有一个代码已经将服务的费率和指定的数量相乘 但在其他情况下要在数据库中捕获它......基于每个“Txt_Qty”条目 Txt_qtyAccomodation...有一个名为“txt_accomodation”的服务条目文本框 Txt_qtyHaematology... 有一个名为“cmb_haematology”的服务条目文本框 以此类推
我还需要记录数量和成本 ....
私有子命令按钮1_Click()
Dim dept, details, service, Quantity, Cost, i As Long
Dim zh As Worksheet, LastRow As Long
Set zh = ThisWorkbook.Sheets("PublicDatabase")
LastRow = zh.Cells(Rows.Count, "A").End(xlUp).Row + 1
dept = Array("Accomodation", "Consultation", "Haematology", _
"Histopathology", "Nursingcare", "Others1", _
"Others2", "Microbiology", "Reviews", "Radiology1", "Radiology2", "Radiology3", "Pharmacy1", _
"Pharmacy2", "Pharmacy3", "Phamacy4", "Pharmacy5", "Pharmacy6")
service = Array(Me.txt_initialconsultation.Value, Me.txt_Review.Value, Me.txt_nursingCare.Value, _
Me.txt_Accomodation.Value, Me.cmb_haematology.Value, Me.cmb_histopathology.Value, Me.cmb_Microbiology, _
Me.cmb_Other1.Value, Me.cmb_other2.Value, Me.Cmb_Radiology1.Value, Me.Cmb_Radiology2.Value, _
Me.Cmb_radiology3.Value, Me.Cmb_Pharmacy1.Value, Me.Cmb_Pharmacy2.Value, Me.Cmb_Pharmacy3.Value, _
Me.Cmb_Pharmacy4.Value, Me.Cmb_Pharmacy5.Value, Me.Cmb_Pharmacy6.Value)
Quantity = Array(Me.txt_QtyAccomodation.Value, Me.txt_QtyConsultation.Value, Me.txt_QtyHaematology.Value, _
Me.txt_QtyHistopathology.Value, Me.txt_QtyMicrobiology.Value, Me.txt_QtyNursingcare.Value, Me.txt_QtyOthers1.Value, _
Me.txt_QtyOthers2.Value, Me.txt_QtyPhamacy4.Value, Me.txt_QtyPharmacy1.Value, Me.txt_QtyPharmacy2.Value, Me.txt_QtyPharmacy3.Value, _
Me.txt_QtyPharmacy5.Value, Me.txt_QtyPharmacy6.Value, Me.txt_QtyRadiology1.Value, Me.txt_QtyRadiology2.Value, Me.txt_QtyRadiology3, _
Me.txt_QtyReviews.Value)
Cost = Array(Me.txt_costAccomodation.Value, Me.txt_CostCOnsultation.Value, Me.txt_CostHaematology.Value, _
Me.txt_CostHistopathology.Value, Me.txt_CostMicrobiology.Value, Me.txt_CostOthers1.Value, _
Me.txt_CostNursingCare.Value, Me.txt_CostOthers2.Value, Me.txt_CostPharmacy1.Value, Me.txt_CostPharmacy2.Value, _
Me.txt_CostPharmacy3.Value, Me.txt_CostPharmacy4.Value, Me.txt_CostPharmacy5.Value, Me.txt_CostPharmacy6.Value, _
Me.txt_CostRadiology1.Value, Me.txt_CostRadiology2.Value, Me.txt_CostRadiology3.Value)
details = PatientDetails()
Dim ccont As Control
For i = 0 To UBound(dept)
Set ccont = Me.Controls("Txt_Qty" & dept(i))
If ccont.Value <> "" Then
details(1, 1) = LastRow - 1
zh.Cells(LastRow, 1).Resize(, 18) = details
zh.Cells(LastRow, 19) = service
zh.Cells(LastRow, 20) = Quantity
zh.Cells(LastRow, 22) = Cost
LastRow = LastRow + 1
End If
Next
MsgBox "Entered", vbInformation
结束子
【问题讨论】:
-
除了您的代码中使用的文本框之外,是否还有其他文本框,可能是空的?我的意思是,它应该被允许为空......如果所有的文本框都应该检查是否为空,为什么还要计算它们?
-
应该是
Dim ccont As Controlsingular -
计算其他中空文本框的数量以使用该值来知道行数患者详细信息将在数据库(电子表格)中重复......所以在大图中,当用户输入5种不同的服务在表格上...它可以根据输入的文本框的数量重复患者详细信息(意味着有服务)