Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Private WithEvents ligardb As ADODB.Connection
- Private WithEvents RecordDB As ADODB.Recordset
- Dim mblnAddMode As Boolean
- Private Sub Command1_Click()
- Dim strConnect As String
- Dim user_id As String
- Dim pass As String
- user_id = "jeff"
- pass = "123"
- strConnect = "DRIVER={MySQL ODBC 3.51 Driver};user =" & user_id & ";password=" & pass & _
- ";server=localhost; Database = dbusers"
- Set ligardb = New ADODB.Connection
- ligardb.CursorLocation = adUseClient
- ligardb.Open strConnect
- Set RecordDB = New ADODB.Recordset
- RecordDB.CursorType = adOpenStatic
- RecordDB.CursorLocation = adUseClient
- RecordDB.LockType = adLockPessimistic
- RecordDB.Source = "select * from users"
- RecordDB.ActiveConnection = ligardb
- RecordDB.Open
- Command1.Enabled = False
- Command2.Enabled = True
- Frame1.Visible = True
- Command8.Visible = True
- Command10.Visible = True
- Command11.Visible = True
- Command4.Enabled = True
- Command5.Enabled = True
- Command6.Enabled = True
- Command7.Enabled = True
- carregaregistos
- End Sub
- Private Sub gravar()
- RecordDB.Fields("ID").Value = Val(Text3.Text)
- RecordDB.Fields("Nome").Value = Text4.Text
- RecordDB!Morada = Text5.Text
- RecordDB!Data = CDate(Text6.Text)
- RecordDB.Fields("Password").Value = Text7.Text
- End Sub
- Private Sub Command10_Click()
- Dim g As Integer
- g = MsgBox("Irá editar o dado ja existente. Tem a certeza que quer guardar?", vbYesNo, "Guardar?")
- If g = vbYes Then
- If Text3.Text <> "" And Text4 <> "" And Text5 <> "" Then
- Call gravar
- RecordDB.Update
- Else
- MsgBox "Falta informar dados !!!!", vbCritical, "Incluindo dados"
- RecordDB.CancelUpdate
- mblnAddMode = False
- Exit Sub
- End If
- mblnAddMode = False
- End If
- End Sub
- Private Sub Command11_Click()
- If MsgBox("Confirma Exclusão deste Registro ? ", vbYesNo, "Excluir Registros") = vbYes Then
- On Error Resume Next
- RecordDB.Delete
- RecordDB.Update
- End If
- End Sub
- Private Sub Command2_Click()
- ligardb.Close
- Set ligardb = Nothing
- Command2.Enabled = False
- Command1.Enabled = True
- Command2.Enabled = False
- Command4.Enabled = False
- Command5.Enabled = False
- Command6.Enabled = False
- Command7.Enabled = False
- Frame1.Visible = False
- Command8.Visible = False
- Command10.Visible = False
- Command11.Visible = False
- End Sub
- Private Sub Command3_Click()
- Dim terminar As Integer
- terminar = MsgBox("Deseja mesmo sair da aplicação?", vbYesNo, "Sair?")
- If terminar = vbYes Then
- End
- Else
- If terminar = vbNo Then
- MsgBox ("Clique OK para continuar")
- End If
- End If
- End Sub
- Private Sub Command4_Click()
- If RecordDB.BOF = False Then
- RecordDB.MovePrevious
- If RecordDB.BOF = True Then
- RecordDB.MoveFirst
- End If
- Else
- If RecordDB.EOF Then
- MsgBox ("Não há dados no Arquivo!")
- Else
- RecordDB.MoveFirst
- End If
- End If
- carregaregistos
- End Sub
- Private Sub Command5_Click()
- If RecordDB.EOF = True Then
- MsgBox "Não há dados no Arquivo!", , "Sem dados !"
- Else
- RecorDB.MoveNext
- carregaregistos
- EndIf
- End Sub
- Private Sub Command6_Click()
- If RecordDB.BOF = False Then
- RecordDB.MoveFirst
- ElseIf RecordDB.BOF = True _
- And RecordDB.EOF = True Then
- MsgBox "Não há dados no Arquivo!", , "Sem dados !"
- End If
- carregaregistos
- End Sub
- Private Sub Command7_Click()
- If RecordDB.EOF = False Then
- RecordDB.MoveLast
- ElseIf RecordDB.BOF = True _
- And RecordDB.EOF = True Then
- MsgBox "Não há dados no Arquivo!", , "Sem dados !"
- End If
- carregaregistos
- End Sub
- Private Sub carregaregistos()
- If RecordDB.BOF = True Or RecordDB.EOF = True Then
- Exit Sub
- End If
- Text3.Text = RecordDB.Fields("ID").Value & " "
- Text4.Text = RecordDB!nome & " "
- Text5.Text = RecordDB!Morada & " "
- Text6.Text = RecordDB!Data & " "
- Text7.Text = RecordDB!Password & " "
- End Sub
- Private Sub Command8_Click()
- RecordDB.AddNew
- Call gravar
- RecordDB.Update
- End Sub
- Private Sub Form_Load()
- Command2.Enabled = False
- Frame1.Visible = False
- Command8.Visible = False
- Command10.Visible = False
- Command11.Visible = False
- End Sub
Add Comment
Please, Sign In to add comment