erro de compilação ...
 
Notifications
Clear all

erro de compilação variavel não definida

2 Posts
2 Usuários
0 Reactions
973 Visualizações
(@andersonps)
Posts: 4
New Member
Topic starter
 

Estou acompanhando umas video aulas e não consigo inserir os dados no banco com o meu botão 5 que serve para gravar dados na minha plan2 está como no video mas me retorna o erro do titulo.

segue codigo abaixo erro no commandbuton5:


Option Explicit

Private Sub CommandButton1_Click()

TextBox1 = Application.WorksheetFunction.Max(Plan2.Columns(1)) + 1  'chama codigo automático contagem maxima + 1'

TextBox2.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
ComboBox1.Enabled = True
TextBox5.Enabled = True


TextBox2 = ""
TextBox3 = Date 'chama data atual'
TextBox4 = ""
ComboBox1 = ""
TextBox5 = ""

CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True


End Sub

Private Sub CommandButton2_Click()

TextBox1.Enabled = True
CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True

End Sub

Private Sub CommandButton3_Click()

TextBox1.Enabled = True
CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True
End Sub

Private Sub CommandButton4_Click()

TextBox1.Enabled = True
CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True
End Sub

Private Sub CommandButton5_Click()


 a = Application.WorksheetFunction.CountA(Plan2.Columns(1)) + 1 'Conta dados até a ultima linha pegando coluna 1 Cadastro (Plan2) como referencia.'

Plan2.Cells(a, 1) = TextBox1.Text
Plan2.Cells(a, 2) = TextBox2.Text  'Insere dados no banco'
Plan2.Cells(a, 3) = TextBox3.Text
Plan2.Cells(a, 4) = TextBox4.Text
Plan2.Cells(a, 5) = ComboBox1.Text
Plan2.Cells(a, 6) = TextBox5.Text

End Sub

Private Sub CommandButton6_Click()

TextBox1 = ""
TextBox2 = ""
TextBox3 = ""    'LIMPA TEXT'
TextBox4 = ""
TextBox5 = ""
ComboBox1 = ""

TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False  'DESABILITA TEXT'
TextBox4.Enabled = False
TextBox5.Enabled = False
ComboBox1.Enabled = False

CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton3.Enabled = True  'HABILITA BOTÃO'
CommandButton4.Enabled = True
CommandButton5.Enabled = False
CommandButton6.Enabled = False



End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
ComboBox1.AddItem "TECDOS"

End Sub


 
Postado : 15/02/2016 9:33 pm
(@alvaro)
Posts: 78
Trusted Member
 

Veja se resolve.
Caso tenha resolvido, não esqueça de marcar o tópico como resolvido.

Option Explicit

Private Sub CommandButton1_Click()

TextBox1 = Application.WorksheetFunction.Max(Plan2.Columns(1)) + 1  'chama codigo automático contagem maxima + 1'

TextBox2.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
ComboBox1.Enabled = True
TextBox5.Enabled = True


TextBox2 = ""
TextBox3 = Date 'chama data atual'
TextBox4 = ""
ComboBox1 = ""
TextBox5 = ""

CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True


End Sub

Private Sub CommandButton2_Click()

TextBox1.Enabled = True
CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True

End Sub

Private Sub CommandButton3_Click()

TextBox1.Enabled = True
CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True
End Sub

Private Sub CommandButton4_Click()

TextBox1.Enabled = True
CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False
CommandButton5.Enabled = True
CommandButton6.Enabled = True
End Sub

Private Sub CommandButton5_Click()

Dim a
 a = Application.WorksheetFunction.CountA(Plan2.Columns(1)) + 1 'Conta dados até a ultima linha pegando coluna 1 Cadastro (Plan2) como referencia.'

Plan2.Cells(a, 1) = TextBox1.Text
Plan2.Cells(a, 2) = TextBox2.Text  'Insere dados no banco'
Plan2.Cells(a, 3) = TextBox3.Text
Plan2.Cells(a, 4) = TextBox4.Text
Plan2.Cells(a, 5) = ComboBox1.Text
Plan2.Cells(a, 6) = TextBox5.Text

End Sub

Private Sub CommandButton6_Click()

TextBox1 = ""
TextBox2 = ""
TextBox3 = ""    'LIMPA TEXT'
TextBox4 = ""
TextBox5 = ""
ComboBox1 = ""

TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False  'DESABILITA TEXT'
TextBox4.Enabled = False
TextBox5.Enabled = False
ComboBox1.Enabled = False

CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton3.Enabled = True  'HABILITA BOTÃO'
CommandButton4.Enabled = True
CommandButton5.Enabled = False
CommandButton6.Enabled = False

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
ComboBox1.AddItem "TECDOS"

End Sub
 
Postado : 15/02/2016 9:39 pm