Caro Alexandre
De uma olhada neste código que eu fiz.
Private Sub CommandButton1_Click()
'Cadastro
'***************************
'Inserir os Dados no banco
'de dados Access
'***************************
Dim cx As New ClasseConexao
Dim banco As ADODB.Recordset
Dim sql As String
cont = 1
Z = CDbl(TextBox31)
If Z > 1 Then
For x = 1 To Z '< Z Then
sql = "INSERT INTO movimento(nome, data, valor, conta, cheque, tipo, pago, copia, semana)"
sql = sql & " VALUES ("
sql = sql & " '" & Me.TextBox1.Text & "'"
sql = sql & ", '" & Me.TextBox2.Text & "'"
sql = sql & ", '" & Me.TextBox3.Text & "'"
sql = sql & ", '" & Me.ComboBox1.Text & "'"
sql = sql & ", '" & Me.TextBox4.Text & "'"
sql = sql & ", '" & Me.ComboBox2.Text & "'"
sql = sql & ", '" & Me.TextBox5.Text & "'"
sql = sql & ", '" & Me.TextBox12.Text & "'"
sql = sql & ", '" & Me.TextBox2.Text & "'"
sql = sql & " )"
Set banco = New ADODB.Recordset
'***********************************************
'Verificar se algum campo esta sem preenchimento
'***********************************************
If Me.TextBox1 = Empty Or Me.TextBox2 = Empty Or Me.TextBox3 = Empty Then
MsgBox "Todos os dados devem ser preenchidos"
Else
cx.Conectar
On Error Resume Next
banco.Open sql, cx.Conn
'aqui ele soma 30 dias ao textbox
Me.TextBox2.Text = CDate(TextBox2.Text) + 30
cont = cont + 1
End If
Next x
If Me.TextBox1 = Empty Or Me.TextBox2 = Empty Or Me.TextBox3 = Empty Then
MsgBox "Todos os dados devem ser preenchidos"
Else
Me.TextBox1 = Empty
Me.TextBox2 = Empty
Me.TextBox3 = Empty
Me.TextBox4 = Empty
Me.TextBox5 = Empty
Me.TextBox12 = Empty
Me.ComboBox1 = ""
Me.ComboBox2 = ""
Me.TextBox1.SetFocus
MsgBox "Movimento Cadastrado com Êxito"
Set banco = Nothing
cx.Desconectar
End If
Else
sql = "INSERT INTO movimento(nome, data, valor, conta, cheque, tipo, pago, copia, semana)"
sql = sql & " VALUES ("
sql = sql & " '" & Me.TextBox1.Text & "'"
sql = sql & ", '" & Me.TextBox2.Text & "'"
sql = sql & ", '" & Me.TextBox3.Text & "'"
sql = sql & ", '" & Me.ComboBox1.Text & "'"
sql = sql & ", '" & Me.TextBox4.Text & "'"
sql = sql & ", '" & Me.ComboBox2.Text & "'"
sql = sql & ", '" & Me.TextBox5.Text & "'"
sql = sql & ", '" & Me.TextBox12.Text & "'"
sql = sql & ", '" & Me.TextBox2.Text & "'"
sql = sql & " )"
Set banco = New ADODB.Recordset
'***********************************************
'Verificar se algum campo esta sem preenchimento
'***********************************************
If Me.TextBox1 = Empty Or Me.TextBox2 = Empty Or Me.TextBox3 = Empty Then
MsgBox "Todos os dados devem ser preenchidos"
Else
cx.Conectar
On Error Resume Next
banco.Open sql, cx.Conn
Me.TextBox1 = Empty
Me.TextBox2 = Empty
Me.TextBox3 = Empty
Me.TextBox4 = Empty
Me.TextBox5 = Empty
Me.TextBox12 = Empty
Me.ComboBox1 = ""
Me.ComboBox2 = ""
Me.TextBox1.SetFocus
MsgBox "Movimento Cadastrado com Êxito"
Set banco = Nothing
cx.Desconectar
End If
End If
End Sub