我用不同表中的数字计算概率。每个客户都有一个专用于文档编号的字母。这些字母有一个概率(0/ 0.3 或 0.7)。我是 Vba 的新手,我真的不知道为什么我会收到这个错误,或者我该如何解决它。
Dim Sum As Double
Dim CB As Double
Dim Csize As Double
Dim USp As Double
Dim DocCat As String
Sum = 0
'CB Loop - Go through all customers in CArray and get the document letter corresponding to the document number in the textbox named SBBox
Dim CArray(1 To 5) As String
CArray(1) = "FF"
CArray(2) = "GG"
CArray(3) = "HH"
CArray(4) = "JJ"
CArray(5) = "DD"
Dim customer As Variant
For Each customer In CArray
'Get portion from customer table by corresponding the customer name with name in array. Here is my problem at the moment
Csize = DLookup("[portion]", "tblCustomer", "[sName]" = customer)
'get document letter from table customer depending on name from array. The table contaning the DocLetters is named the same as in the array (e.g. FF GG HH and so on)
DocCat = DLookup("[DocLetter]", customer, "[Doc Number]= SBBox.Value")
'Use the DocCat to categoriez "bad", "good", "great" Letter
If StrComp(DocCat, "A") Or StrComp(DocCat, "B") Or StrComp(DocCat, "C") Then
CB = 0
ElseIf DocCat = StrComp(DocCat, "E") Or StrComp(DocCat, "F") or Null Then
CB = 0.3
Else: CB = 0.7
End If
'get the usage amount from the tblUsage depending from the PartNumber in PNBox
USp = DLookup("[Rel]", "tblUsage", "[Material]=PNBox.Value")
'sum up all poducts from each loop
Sum = Sum + CB * Csize * USp
Next customer
'print out inTextbox
Sum = TextBox1.Text
End Sub
我在 Csize = DLookup 上收到错误“无效使用 Null”......我猜是因为标准
我不可能有任何表名,并且代码将在未来扩展。
任何帮助,将不胜感激。