Vídeo recomendado
https://youtu.be/diWPPPhW-9E

Erro Objeto é Obrigatório Userform - Novo Frame

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
patrickão
Colaborador
Colaborador
Mensagens: 15
Registrado em: Ter Jul 01, 2014 9:35 pm

Erro Objeto é Obrigatório Userform - Novo Frame

Mensagem por patrickão »

Olá Pessoal.

Estou tentando criar um userform para melhorar minha entrada de dados.

Quando excuto o userform2 eu adiciono os valores no textbox (Numero da OV - qualquer valor) e no textbox do 1º Evento. Quando clico em adicionar, o programa adiciona um novo frame e textbox e labels para eu adicionar outro evento de pagamento.
Aí quando entro com valor nos textbox do 2º evento e clico em Ok o programa deveria plotar o que valores digitados pelo usuário, porém da erro de "Objeto é obrigatório".

Alguém poderia me ajudar?
Valeu galera!!!

Segue o código.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub UserForm2_Initialize()

OVTextBox1.Value = ""

PorcentagemTextBox1.Value = ""
DiasTextBox1.Value = ""

PorcentagemTextBox2.Value = ""
DiasTextBox2.Value = ""

PorcentagemTextBox3.Value = ""
DiasTextBox3.Value = ""

PorcentagemTextBox4.Value = ""
DiasTextBox4.Value = ""

PorcentagemTextBox5.Value = ""
DiasTextBox5.Value = ""

End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Adicionar_Click()

'Dim TempForm As Object
Dim txtB1 As MSForms.TextBox
Dim txtB2 As MSForms.TextBox
Dim NewFrame As MSForms.Frame
Dim NewLabel1 As MSForms.Label
Dim NewLabel2 As MSForms.Label
Dim NewLabel3 As MSForms.Label
Dim i As Integer, Rw As Integer

i = 1

Set NewFrame = Me.Controls.Add("Forms.Frame.1")
Set NewLabel1 = NewFrame.Controls.Add("Forms.Label.1", "Label1", True)
Set NewLabel2 = NewFrame.Controls.Add("Forms.Label.1", "Label2", True)
Set NewLabel3 = NewFrame.Controls.Add("Forms.Label.1", "Label3", True)
Set txtB1 = NewFrame.Controls.Add("Forms.TextBox.1", "PorcentagemTextBox2", True)
Set txtB2 = NewFrame.Controls.Add("Forms.TextBox.1", "DiasTextBox2", True)


With NewFrame
.Name = "Frame2"
.Height = 78
.Width = 372
.Left = 12
.Top = 186

NewLabel1.Caption = "" & i + 1 & "º Evento de Pagamento"
NewLabel1.Height = 36
NewLabel1.Left = 12
NewLabel1.Top = 18
NewLabel1.Width = 96
NewLabel1.Font = Tahoma
NewLabel1.ForeColor = &H0&
NewLabel1.Font.Bold = True
NewLabel1.Font.Size = 14
NewLabel1.TextAlign = fmTextAlignCenter

NewLabel2.Caption = "Valor a receber (%)"
NewLabel2.Height = 24
NewLabel2.Left = 108
NewLabel2.Top = 6
NewLabel2.Width = 96
NewLabel2.Font = Tahoma
NewLabel2.ForeColor = &H0&
NewLabel2.Font.Bold = True
NewLabel2.Font.Size = 10
NewLabel2.TextAlign = fmTextAlignCenter

NewLabel3.Caption = "Dias para receber o " & i + 1 & "º Evento de Pagamento"
NewLabel3.Height = 24
NewLabel3.Left = 204
NewLabel3.Top = 6
NewLabel3.Width = 162
NewLabel3.Font = Tahoma
NewLabel3.ForeColor = &H0&
NewLabel3.Font.Bold = True
NewLabel3.Font.Size = 10
NewLabel3.TextAlign = fmTextAlignCenter

txtB1.Height = 15.75
txtB1.Left = 138
txtB1.Top = 48
txtB1.Width = 30

txtB2.Height = 15.75
txtB2.Left = 264
txtB2.Top = 48
txtB2.Width = 30

End With


End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Cancelar_Click()

Unload Me

End Sub
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Ok_Click()

Dim Numero As Integer, strPrompt As String, strTitle As String, OV As String, OVdig As String
Dim Rw As Integer, Sheet As String

Sheet = ActiveSheet.Name
Worksheets(Sheet).Activate
strPrompt = " Entre com o número da Ordem de Venda do pedido. "
strTitle = "Mensagem de Alerta"
Rw = 34

If OVTextBox1.Value = "" Then

Numero = MsgBox(strPrompt, vbOKOnly, strTitle)

End If

OVdig = OVTextBox1.Value
OV = Worksheets(Sheet).Cells(Rw, 2).Value

Do While OV <> ""

If OV = OVTextBox1.Value Then
'Plota o 1º Evento de Pagamento
Worksheets(Sheet).Cells(Rw, 40).Value = PorcentagemTextBox1.Value
Worksheets(Sheet).Cells(Rw, 41).Value = DiasTextBox1.Value
'Plota o 2º Evento de Pagamento
Worksheets(Sheet).Cells(Rw, 42).Value = PorcentagemTextBox2.Value
Worksheets(Sheet).Cells(Rw, 43).Value = DiasTextBox2.Value
'Plota o 3º Evento de Pagamento
Worksheets(Sheet).Cells(Rw, 44).Value = PorcentagemTextBox3.Value
Worksheets(Sheet).Cells(Rw, 45).Value = DiasTextBox3.Value
'Plota o 4º Evento de Pagamento
Worksheets(Sheet).Cells(Rw, 46).Value = PorcentagemTextBox4.Value
Worksheets(Sheet).Cells(Rw, 47).Value = DiasTextBox4.Value
'Plota o 5º Evento de Pagamento
Worksheets(Sheet).Cells(Rw, 48).Value = PorcentagemTextBox5.Value
Worksheets(Sheet).Cells(Rw, 49).Value = DiasTextBox5.Value
Rw = Rw + 1
OV = Worksheets(Sheet).Cells(Rw, 2).Value
Else
Rw = Rw + 1
OV = Worksheets(Sheet).Cells(Rw, 2).Value
End If
Loop

Unload Me

End Sub


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Avatar do usuário
skuma
Colaborador
Colaborador
Mensagens: 25
Registrado em: Qui Mai 02, 2013 2:03 pm

Re: Erro Objeto é Obrigatório Userform - Novo Frame

Mensagem por skuma »

Se possível anexa o arquivo para da uma olhada, assim fica mais facil dizer o que pode ser.

Outro ponto, quando você manda debugar o código onde ele para?


Responder