我通過保持所有的代碼,除了原來的形式在標籤上解決了這個問題。最新的錯誤是圍繞着變換的變量進行的。現在的作品完美(下圖):
Form1中
Public Price As Double
Public Percent As Double
Public Cost As Currency
Public Description As String
Public MonthCode As Integer
Public Pricer As String
Public ItemNumber As Double
Private Sub UserForm_Initialize()
Pricer = InputBox("Enter Your Pricer Number", vbOKOnly, "")
If Len(Pricer) = 0 Then 'Checking if Length of name is 0 characters
End
Else
End If
End Sub
Private Sub cmdSearch_Click()
Dim Response As Long
Dim NotFound As Integer
Dim arr As Variant
Dim i As Long
Dim str1 As String, str2 As String, str3 As String
lbxCost.BackColor = &H80000005
lbxCost.Locked = False
NotFound = 0
ActiveWorkbook.Sheets("Items").Activate
Response = Val("0" & Replace(txtItemNumber.Text, "-", ""))
ItemNumber = Response
If Response <> False Then
With ActiveSheet
arr = .Range("A2:D" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With
For i = 1 To UBound(arr)
If arr(i, 1) = Response Then
str1 = IIf(str1 = "", arr(i, 2), str1 & "|" & arr(i, 2))
str2 = IIf(str2 = "", arr(i, 3), str2 & "|" & arr(i, 3))
str3 = IIf(str3 = "", arr(i, 4), str3 & "|" & arr(i, 4))
End If
Next
If str1 = "" Then
MsgBox "Item Number Not Found!", vbExclamation
NotFound = 1
txtItemNumber.Text = ""
txtItemNumber.SetFocus
Else
Frame1.Visible = True
lbxDescription.List = Split(str1, "|")
lbxCost.List = Split(str2, "|")
ListBox3.List = Split(str3, "|")
End If
End If
lbxCost.ListIndex = 0
End Sub
Private Sub lbxCost_Click()
Frame2.Visible = True
End Sub
Private Sub lbxPercent_Click()
Frame3.Visible = True
lbxCost.BackColor = &H80000004
lbxCost.Locked = True
For x = 0 To lbxCost.ListCount - 1
If lbxCost.Selected(x) = True Then
Cost = lbxCost.List(x)
Description = lbxDescription.List(x)
End If
Next x
For y = 0 To lbxPercent.ListCount - 1
If lbxPercent.Selected(y) = True Then
Percent = lbxPercent.List(y)
End If
Next y
lblPrice.Caption = (Round(Cost * (1 + (Percent/100)), 0)) - 0.01
Price = lblPrice.Caption
lblItemNumber.Caption = txtItemNumber.Text
lblDescription.Caption = Description
MonthCode = (Year(Now)) + (Month(Now)) - 1765
lblMonthCode.Caption = MonthCode
lblPricer.Caption = Pricer
cmdPrint.SetFocus
End Sub
Private Sub cmdPrint_Click()
Dim i As Integer
Dim Howmany As Double
Load frmPopup
Howmany = Val(txtQuantity.Text)
i = 1
Do Until i > Howmany
frmPopup.PrintForm
i = i + 1
Loop
lbxPercent.ListIndex = -1
Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = False
txtItemNumber.Text = ""
txtItemNumber.SetFocus
Unload frmPopup
End Sub
窗口2
Private Sub UserForm_Initialize()
lblPrintMonthCode.Caption = frmClothingPricer.MonthCode
lblPrintPricer.Caption = frmClothingPricer.Pricer
lblPrintCost.Caption = (frmClothingPricer.Cost * 100)
lblPrintDescription.Caption = frmClothingPricer.Description
lblPrintPrice.Caption = frmClothingPricer.Price
lblPrintItemNumber = frmClothingPricer.ItemNumber
End Sub
不要使用[類名來引用形式(http://stackoverflow.com/a/6049062/11683),明確創建實例。 – GSerg
爲什麼要打開表單來打印然後關閉表單? – Davesexcel
它使微小的標籤哈哈,發現它很難打印出我想要的格式。 – instanceoftime