Preciso colocar nesse projeto abaixo as subs para Incluir, Excluir, Salvar, Localizar e Alterar, não sei fazer tem como alguém criar para mim ,
eu já criei os botões mas andei pegando exemplo por ai e não deu certo.
Com isso, acho que é o básico de um projeto e eu vou aprender e assim ir melhorando nas validações.
Até coloquei uma de Procurar mas não dá erro e não procura nada.
Public Conexao As ADODB.Connection
Private RsTabela As ADODB.Recordset
Private Cmd As ADODB.Command
Private Sub Atualizar()
TxtCodigo.Text = RsTabela("codigo")
TxtNome.Text = RsTabela("nome")
TxtObs.Text = RsTabela("obs")
End Sub
Private Sub CmdAnterior_Click()
Set Cmd = New ADODB.Command
Set Cmd.ActiveConnection = Conexao
Cmd.CommandType = adCmdText
Cmd.CommandText = "select * from tabela where codigo=(select max(codigo) from tabela where codigo < ?)"
Cmd.Parameters(0).Value = TxtCodigo.Text
Set RsTabela = Cmd.Execute
If Not RsTabela.EOF Then
Atualizar
End If
RsTabela.Close
Set RsTabela = Nothing
Set Cmd = Nothing
End Sub
Private Sub CmdPrimeiro_Click()
Set RsTabela = New ADODB.Recordset
RsTabela.Open "Select * From Tabela where codigo=(select min(codigo) from tabela)", Conexao, adOpenDynamic
If Not RsTabela.EOF Then
Atualizar
End If
RsTabela.Close
Set RsTabela = Nothing
End Sub
Private Sub CmdProximo_Click()
Set Cmd = New ADODB.Command
Set Cmd.ActiveConnection = Conexao
Cmd.CommandType = adCmdText
Cmd.CommandText = "select * from tabela where codigo=(select min(codigo) from tabela where codigo > ?)"
Cmd.Parameters(0).Value = TxtCodigo.Text
Set RsTabela = Cmd.Execute
If Not RsTabela.EOF Then
Atualizar
End If
RsTabela.Close
Set RsTabela = Nothing
Set Cmd = Nothing
End Sub
Private Sub CmdUltimo_Click()
Set RsTabela = New ADODB.Recordset
RsTabela.ActiveConnection = Conexao
RsTabela.CursorLocation = adUseClient
RsTabela.CursorType = adOpenDynamic
RsTabela.Open "Select * From Tabela where codigo=(select max(codigo) from tabela)"
If Not RsTabela.EOF Then
Atualizar
End If
RsTabela.Close
Set RsTabela = Nothing
End Sub
_______________________________________________________________________
Private Sub Command1_Click()
End
End Sub
Private Sub Command2_Click()
MsgBox "Não foi desenvolvido ainda!!!!", vbExclamation, _
"Aviso"
End Sub
Private Sub Command4_Click()
Dim Procurar As String
Procurar = InputBox("Coloque o nome que deseja procurar", , "Aviso")
Set RsTabela = Db.OpenRecordSet("SELECT * FROM Tabela WHERE Nome='" & Procurar & "'", DbOpenDyNaset)
If RsTabela.RecordCount = 0 Then
MsgBox "Registro não encontrado", 64, "Aviso"
Else
TxtCodigo.Text = RsTabela("Codigo")
TxtNome.Text = RsTabela("Nome")
TxtObs.Text = RsTabela("Obs")
End If
End Sub
Private Sub Form_Load()
'abre banco
Set Conexao = New ADODB.Connection
Conexao.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & App.Path & "\banco.mdb"
'Frame1.Enabled = False
CmdPrimeiro_Click
End Sub
Private Sub UltimoCmd_Click()
Set RsTabela = New ADODB.Recordset
RsTabela.ActiveConnection = Conexao
RsTabela.CursorLocation = adUseClient
RsTabela.CursorType = adOpenDynamic
RsTabela.Open "Select * From Tabela where codigo=(select max(codigo) from tabela)"
If Not RsTabela.EOF Then
Atualizar
End If
RsTabela.Close
Set RsTabela = Nothing
End Sub
Pergunta
Flecha
Olá,
Preciso colocar nesse projeto abaixo as subs para Incluir, Excluir, Salvar, Localizar e Alterar, não sei fazer tem como alguém criar para mim ,
eu já criei os botões mas andei pegando exemplo por ai e não deu certo.
Com isso, acho que é o básico de um projeto e eu vou aprender e assim ir melhorando nas validações.
Até coloquei uma de Procurar mas não dá erro e não procura nada.
Public Conexao As ADODB.Connection Private RsTabela As ADODB.Recordset Private Cmd As ADODB.Command Private Sub Atualizar() TxtCodigo.Text = RsTabela("codigo") TxtNome.Text = RsTabela("nome") TxtObs.Text = RsTabela("obs") End Sub Private Sub CmdAnterior_Click() Set Cmd = New ADODB.Command Set Cmd.ActiveConnection = Conexao Cmd.CommandType = adCmdText Cmd.CommandText = "select * from tabela where codigo=(select max(codigo) from tabela where codigo < ?)" Cmd.Parameters(0).Value = TxtCodigo.Text Set RsTabela = Cmd.Execute If Not RsTabela.EOF Then Atualizar End If RsTabela.Close Set RsTabela = Nothing Set Cmd = Nothing End Sub Private Sub CmdPrimeiro_Click() Set RsTabela = New ADODB.Recordset RsTabela.Open "Select * From Tabela where codigo=(select min(codigo) from tabela)", Conexao, adOpenDynamic If Not RsTabela.EOF Then Atualizar End If RsTabela.Close Set RsTabela = Nothing End Sub Private Sub CmdProximo_Click() Set Cmd = New ADODB.Command Set Cmd.ActiveConnection = Conexao Cmd.CommandType = adCmdText Cmd.CommandText = "select * from tabela where codigo=(select min(codigo) from tabela where codigo > ?)" Cmd.Parameters(0).Value = TxtCodigo.Text Set RsTabela = Cmd.Execute If Not RsTabela.EOF Then Atualizar End If RsTabela.Close Set RsTabela = Nothing Set Cmd = Nothing End Sub Private Sub CmdUltimo_Click() Set RsTabela = New ADODB.Recordset RsTabela.ActiveConnection = Conexao RsTabela.CursorLocation = adUseClient RsTabela.CursorType = adOpenDynamic RsTabela.Open "Select * From Tabela where codigo=(select max(codigo) from tabela)" If Not RsTabela.EOF Then Atualizar End If RsTabela.Close Set RsTabela = Nothing End Sub _______________________________________________________________________ Private Sub Command1_Click() End End Sub Private Sub Command2_Click() MsgBox "Não foi desenvolvido ainda!!!!", vbExclamation, _ "Aviso" End Sub Private Sub Command4_Click() Dim Procurar As String Procurar = InputBox("Coloque o nome que deseja procurar", , "Aviso") Set RsTabela = Db.OpenRecordSet("SELECT * FROM Tabela WHERE Nome='" & Procurar & "'", DbOpenDyNaset) If RsTabela.RecordCount = 0 Then MsgBox "Registro não encontrado", 64, "Aviso" Else TxtCodigo.Text = RsTabela("Codigo") TxtNome.Text = RsTabela("Nome") TxtObs.Text = RsTabela("Obs") End If End Sub Private Sub Form_Load() 'abre banco Set Conexao = New ADODB.Connection Conexao.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & App.Path & "\banco.mdb" 'Frame1.Enabled = False CmdPrimeiro_Click End Sub Private Sub UltimoCmd_Click() Set RsTabela = New ADODB.Recordset RsTabela.ActiveConnection = Conexao RsTabela.CursorLocation = adUseClient RsTabela.CursorType = adOpenDynamic RsTabela.Open "Select * From Tabela where codigo=(select max(codigo) from tabela)" If Not RsTabela.EOF Then Atualizar End If RsTabela.Close Set RsTabela = Nothing End SubFlecha
Editado por FlechaLink para o comentário
Compartilhar em outros sites
6 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.