위상의 날짜를 순환하려면 스핀 단추를 사용하고 있습니다. 인덱스 값이있는 customtextboxcollection 컬렉션에서 항목을 호출하면 "Object Required"오류가 발생합니다. 스핀 단추와 값이 변경된 텍스트 상자는 모두 UserForm1이라는 UserForm에 표시된 동적으로 만들어진 컨트롤입니다.동적으로 생성 된 컨트롤을 컬렉션에서 다른 동적으로 생성 된 컨트롤의 클래스를 참조 할 때 'Object Required'오류가 발생했습니다.
customtextbox 수집 실행의 항목을 작성하는 서브 스핀 버튼을 클릭하기 전에 :
Public WithEvents spin As MSForms.SpinButton
Private Sub spin_Click()
UserForm1.CommandButton3.Enabled = True
End Sub
Private Sub spin_SpinDown()
x = 0
Do
x = x + 1
Loop Until spin.name = "SpinButton" & x
Dim spindate As Date
spindate = customtextboxcollection.Item(x).ctext.Value 'The error occurs here.
customtextboxcollection.Item(x).ctext.Value = DateAdd("m", -1, spindate)
End Sub
:
이
Dim customtextboxcollection As Collection
Dim spinbuttoncollection As Collection
Public Sub ComboBox1_Click() 'When a person is selected to enter hours for an employee from a combobox, it triggers the creation of the controls
Sheet1.Activate
CommandButton1.Enabled = True 'Enable the OK and Apply buttons when personnel title is selected.
UserForm1.Label2.Visible = True
UserForm1.ratebox.Visible = True
QuantityLabel.Visible = True
quantitybox.Visible = True
'The variables below are to access the table where I store saved information regarding the project phases I will add hours to.
Dim counter As Integer
counter = 6 'The index of the first row for phases
Dim phasecolumn As Integer
phasecolumn = 3 'The index of the column containing the phases
Dim checkboxnumber As Integer
checkboxnumber = 1 'This is the number needed to distinguish between the checkboxes that appear/disappear.
phasestartcolumn = 4
phaseendcolumn = 5
Dim customtextboxHandler As cCustomTextBoxHandler
Set customtextboxcollection = New Collection 'Sets the previously created collection
Dim spinbuttonHandler As cSpinButtonHandler 'This is my spin button handler class
Set spinbuttoncollection = New Collection 'Sets the previously created collection
'This Do-Loop locates a row on the table with saved information
Do
If (Sheet3.Cells(savedpersonnelrow, savedpersonnelcolumn) = ComboBox1.Value) Then
storagerow = savedpersonnelrow
lastcomboboxvalue = ComboBox1.Value
Exit Do
End If
savedpersonnelrow = savedpersonnelrow + 1
Loop Until (savedpersonnelrow = 82)
Sheet1.Activate
'These sections create the controls depending on the number of phases saved.
Set spin = UserForm1.Controls.Add("Forms.SpinButton.1")
With spin
.name = "SpinButton" & checkboxnumber
.Left = 365
.Top = topvalue + 6
.Height = 15
.Width = 40
'.Value = Sheet3.Cells(storagerow, savedphasecolumn + checkboxnumber)
'Sheet1.Activate
Dim phasestart As Date
phasestart = Sheet1.Cells(counter, phasestartcolumn).Value
Dim phaseend As Date
phaseend = Sheet1.Cells(counter, phaseendcolumn).Value
spin.Min = phasestart
spin.Max = phaseend
spin.Orientation = fmOrientationVertical
'Do
'.AddItem Format(phasestart, "mmm-yy")
'phasestart = DateAdd("m", 1, phasestart)
'Loop Until (Month(phaseend) = Month(phasestart) And Year(phaseend) = Year(phasestart))
Set spinbuttonHandler = New cSpinButtonHandler
Set spinbuttonHandler.spin = spin
spinbuttoncollection.Add spinbuttonHandler
End With
Set ctext = UserForm1.Controls.Add("Forms.TextBox.1")
With ctext
.name = "CustomTextbox" & checkboxnumber
.Left = 470
.Top = topvalue + 6
.Height = 15
.Width = 40
.Value = phasestart
Set customtextboxHandler = New cCustomTextBoxHandler
Set customtextboxHandler.ctext = ctext
customtextboxcollection.Add customtextboxHandler
End With
topvalue = topvalue + 15
counter = counter + 1
checkboxnumber = checkboxnumber + 1
Loop Until counter = 14
End Sub
이 cSpinButtonHandler라는 내 수업에서, 나는 그것과 관련이 customtextboxcollection 객체를 참조는 해당 스핀 버튼의
왜이 참조가 오류를 생성합니까? 그것을 참조하는 올바른 방법은 무엇입니까?
두 개의 별도 컬렉션과 두 개의 다른 클래스를 사용하는 대신 각 컨트롤 쌍 (스핀과 텍스트 상자 하나)을 처리하는 단일 클래스를 만들 수 있습니다. 그것은 각 쌍 사이에 이벤트를 후킹하는 관점에서 다루기가 더 쉬울 것입니다. –
답장을 보내 주셔서 감사합니다. 프로세스를 탐색하는 데 도움이되는 리소스를 참조 할 수 있습니까? 두 컨트롤을 같은 클래스로 변경했지만 여전히 동일한 오류가 발생합니다. 시간 내 주셔서 다시 한번 감사드립니다. – VivaLaTexas