Change Password Form
Source Code For User Change Password
Dim Cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub CmdBatal_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Call Kosong
CmdBatal.Enabled = False
CmdSimpan.Enabled = False
CmdUbah.Enabled = False
End Sub
Private Sub CmdKeluar_Click()
Cnn.Close
Set Cnn = Nothing
Unload Me
End Sub
Private Sub CmdSimpan_Click()
Dim SintakSQL As String
If Text1.Text <> "" Then
Cnn.BeginTrans
If Text3.Visible = True Then
'Mengubah record pada tabel
SintakSQL = " Update members Set " & _
" sandi='" & Text3.Text & "'" & _
" Where member='" & Text1.Text & "'"
'Mengeksekusi perintah SQL
Cnn.Execute (SintakSQL)
End If
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
CmdSimpan.Enabled = False
CmdBatal.Enabled = False
CmdUbah.Enabled = True
Cnn.CommitTrans
End If
actifitas = Replace(SintakSQL, "'", "`", 1, -1)
SintakSQL = " insert into Activity (sandi, activity) values ('" & namauser & "','" & actifitas & "')"
Cnn.Execute (SintakSQL)
End Sub
Private Sub CmdUbah_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
CmdUbah.Enabled = False
CmdSimpan.Enabled = False
CmdBatal.Enabled = False
Call Kosong
End Sub
Private Sub Form_Activate()
Text1.SetFocus
End Sub
Private Sub Form_Load()
'Membuat Sebuah Koneksi
Set Cnn = New ADODB.Connection
With Cnn
.ConnectionString = "provider=SQLOLEDB;" & _
"Data Source=10.11.12.56,1433/Kenari;initial Catalog=Pulsa;" & _
"Trusted Connection=yes; User ID=pulsa; Password=Pulsa123"
.Open
End With
Set rs = New ADODB.Recordset
Text3.Visible = False
Text4.Visible = False
CmdSimpan.Enabled = False
CmdUbah.Enabled = False
CmdBatal.Enabled = False
Me.Top = (Main.ScaleHeight - Me.ScaleHeight) / 2
Me.Left = (Main.ScaleWidth - Me.ScaleWidth) / 2
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub Text1_LostFocus()
Dim Msql As String
'Mengecek ID User/Pemakai
If Text1.Text <> "" Then
Msql = " Select * From members " & _
" Where member='" & Trim(Text1.Text) & "'"
Set rs = Cnn.Execute(Msql)
'Jika User ID tidak Ada
If rs.EOF Then
MsgBox " User ID tidak ada !!!", vbOKOnly + vbExclamation, "Salah Kode ID"
Text1.SetFocus
Else
CmdSimpan.Enabled = True
CmdBatal.Enabled = True
End If
rs.Close
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub Text2_LostFocus()
Dim Msql As String
'Mengecek Password Lama
If Text2.Text <> "" Then
Msql = " Select * from members " & _
" Where member='" & Trim(Text1.Text) & "'"
Set rs = Cnn.Execute(Msql)
'Salah password
If Trim(Text2.Text) <> rs.Fields("sandi") Then
MsgBox "Salah Password", vbOKOnly + vbCritical, "Salah Password Lama"
Text2.Text = ""
Text2.SetFocus
Text3.Visible = False
Text4.Visible = False
'Password lama sesuai
Else
Text3.Visible = True
Text4.Visible = True
Text3.SetFocus
End If
rs.Close
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys vbTab
End If
End Sub
Private Sub Text4_LostFocus()
'Mengecek password sama dengan konfirmasi
If Text3.Text <> "" Then
If Text3.Text <> Text4.Text Then
MsgBox "Password tidak sama", vbOKOnly + vbCritical, "Salah Password"
Text4.SetFocus
End If
End If
End Sub
Sub Kosong()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text3.Visible = False
Text4.Visible = False
End Sub
0 Response to "Change Password Form"
Posting Komentar