Rabu, 02 Januari 2013

login dengan Data base access


  1. Buat desain Form seperti diatas
  2. masukkan coding di bawah ini
Private con As New ADODB.Connection
Private rst As New ADODB.Recordset
Private strconn As String
Private sql As String

Private Sub Connections()
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db.mdb ;Persist Security Info=False;Jet OLEDB"

If con.State = adStateOpen Then
  con.Close
  Set con = New ADODB.Connection
  con.Open strconn
Else
  con.Open strconn
End If
End Sub

Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdLogin_Click()
On Error Resume Next

Static i As Integer

If txtUser.Text = "" Then
  GoSub noacc
  MsgBox "Anda belum memasukkan Nama", vbInformation + vbOKOnly, ":: Informasi ::"
  txtUser.SetFocus
ElseIf txtPass.Text = "" Then
  GoSub noacc
  MsgBox "Anda belum memasukkan Kata Sandi", vbInformation + vbOKOnly, ":: Informasi ::"
  txtPass.SetFocus
Else
  sql = "SELECT * FROM LOGIN WHERE username='" & txtUser.Text & "'"
  Set rst = con.Execute(sql)
  If rst.EOF Then
    GoSub noacc
    MsgBox "Nama atau Kata sandi yang anda masukkan salah", vbInformation + vbOKOnly, ":: Informasi ::"
    txtUser.SetFocus
 
  ElseIf txtPass.Text <> rst("pass") Then
    GoSub noacc
    MsgBox "Nama atau Kata sandi yang anda masukkan salah", vbInformation + vbOKOnly, ":: Informasi ::"
    txtUser.SetFocus
 
  Else
    MsgBox "Selamat anda berhasil login", vbInformation + vbOKOnly, "Informasi"
   Form2.Show
   Form1.Hide
  End If
End If
Exit Sub

noacc:
i = i + 1
If i = 3 Then
  MsgBox "Maaf anda tidak berhak mengakses aplikasi ini !", vbCritical, ":: Gagal ::"
  End
Else
  Return
End If

End Sub

Private Sub Form_Load()
Call Connections
txtUser.Text = ""
txtPass.Text = Empty
End Sub
 Private con As New ADODB.Connection
Private rst As New ADODB.Recordset
Private strconn As String
Private sql As String

Private Sub Connections()
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db.mdb ;Persist Security Info=False;Jet OLEDB"

If con.State = adStateOpen Then
  con.Close
  Set con = New ADODB.Connection
  con.Open strconn
Else
  con.Open strconn
End If
End Sub

Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdLogin_Click()
On Error Resume Next

Static i As Integer

If txtUser.Text = "" Then
  GoSub noacc
  MsgBox "Anda belum memasukkan Nama", vbInformation + vbOKOnly, ":: Informasi ::"
  txtUser.SetFocus
ElseIf txtPass.Text = "" Then
  GoSub noacc
  MsgBox "Anda belum memasukkan Kata Sandi", vbInformation + vbOKOnly, ":: Informasi ::"
  txtPass.SetFocus
Else
  sql = "SELECT * FROM LOGIN WHERE username='" & txtUser.Text & "'"
  Set rst = con.Execute(sql)
  If rst.EOF Then
    GoSub noacc
    MsgBox "Nama atau Kata sandi yang anda masukkan salah", vbInformation + vbOKOnly, ":: Informasi ::"
    txtUser.SetFocus
 
  ElseIf txtPass.Text <> rst("pass") Then
    GoSub noacc
    MsgBox "Nama atau Kata sandi yang anda masukkan salah", vbInformation + vbOKOnly, ":: Informasi ::"
    txtUser.SetFocus
 
  Else
    MsgBox "Selamat anda berhasil login", vbInformation + vbOKOnly, "Informasi"
   Form2.Show
   Form1.Hide
  End If
End If
Exit Sub

noacc:
i = i + 1
If i = 3 Then
  MsgBox "Maaf anda tidak berhak mengakses aplikasi ini !", vbCritical, ":: Gagal ::"
  End
Else
  Return
End If

End Sub

Private Sub Form_Load()
Call Connections
txtUser.Text = ""
txtPass.Text = Empty
End Sub
Private con As New ADODB.Connection
Private rst As New ADODB.Recordset
Private strconn As String
Private sql As String

Private Sub Connections()
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db.mdb ;Persist Security Info=False;Jet OLEDB"

If con.State = adStateOpen Then
  con.Close
  Set con = New ADODB.Connection
  con.Open strconn
Else
  con.Open strconn
End If
End Sub

Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdLogin_Click()
On Error Resume Next

Static i As Integer

If txtUser.Text = "" Then
  GoSub noacc
  MsgBox "Anda belum memasukkan Nama", vbInformation + vbOKOnly, ":: Informasi ::"
  txtUser.SetFocus
ElseIf txtPass.Text = "" Then
  GoSub noacc
  MsgBox "Anda belum memasukkan Kata Sandi", vbInformation + vbOKOnly, ":: Informasi ::"
  txtPass.SetFocus
Else
  sql = "SELECT * FROM LOGIN WHERE username='" & txtUser.Text & "'"
  Set rst = con.Execute(sql)
  If rst.EOF Then
    GoSub noacc
    MsgBox "Nama atau Kata sandi yang anda masukkan salah", vbInformation + vbOKOnly, ":: Informasi ::"
    txtUser.SetFocus
 
  ElseIf txtPass.Text <> rst("pass") Then
    GoSub noacc
    MsgBox "Nama atau Kata sandi yang anda masukkan salah", vbInformation + vbOKOnly, ":: Informasi ::"
    txtUser.SetFocus
 
  Else
    MsgBox "Selamat anda berhasil login", vbInformation + vbOKOnly, "Informasi"
   Form2.Show
   Form1.Hide
  End If
End If
Exit Sub

noacc:
i = i + 1
If i = 3 Then
  MsgBox "Maaf anda tidak berhak mengakses aplikasi ini !", vbCritical, ":: Gagal ::"
  End
Else
  Return
End If

End Sub

Private Sub Form_Load()
Call Connections
txtUser.Text = ""
txtPass.Text = Empty
End Sub

Tidak ada komentar:

Posting Komentar

English French German Spain Italian Dutch Russian Portuguese Japanese Korean Arabic Chinese Simplified
Antispam