Está en la página 1de 3

INGRESAR CLAVE

1.

Option Explicit
2.


3.


4.


5.

Private Sub TxtClave_KeyPress(KeyAscii As Integer)
6.

If KeyAscii = 13 Then
7.

Ingresar_Clave
8.

End If
9.


10.

End Sub
11.


12.

Private Sub CmdSalir_Click()
13.


14.

nc.Close
15.

Set nc = Nothing
16.

End
17.

End Sub
18.


19.

Private Sub CmdIngresar_Click()
20.


21.

If TxtLogin.Text = "" Then
22.

MsgBox "Seleccione el nombre de usuarios", 16,
"Para Ingresar al sistema"
23.

TxtLogin.SetFocus
24.

Exit Sub
25.

End If
26.


27.

If TxtClave.Text = "" Then
28.

MsgBox "Ingrese su clave de acceso", 16, "Para
ingresar al sistema"
29.

TxtClave.SetFocus
30.

Exit Sub
31.

End If
32.

Ingresar_Clave
33.


34.

End Sub
35.


36.

Private Sub Form_Load()
37.

Iniciar_Conexion
38.

Cargar_Usuarios
39.


40.

End Sub
41.


42.

Private Sub Iniciar_Conexion()
43.

Dim sPath As String
44.

sPath = App.Path & "\MiBase.mdb"
45.

With nc
46.

.Provider = "Microsoft.Jet.OLEDB.4.0"
47.

.Properties("Data Source").Value = sPath
48.

.Properties("Persist Security Info").Value = False
49.

.Open
50.

End With
51.

End Sub
52.


53.

Private Sub Cargar_Usuarios()
54.

Dim rs As New ADODB.Recordset
55.


56.

rs.Open "SELECT * FROM usuarios", nc,
adOpenDynamic, adLockOptimistic
57.

While Not rs.EOF
58.

TxtLogin.AddItem rs!nombre
59.

rs.MoveNext
60.

Wend
61.

rs.Close
62.


63.

Set rs = Nothing
64.

End Sub
65.


66.


67.

Private Sub Ingresar_Clave()
68.


69.

Dim rec As New ADODB.Recordset
70.

Dim clav As String
71.

Dim EstM As Boolean
72.


73.


74.

rec.Open "SELECT * FROM usuarios where Clave='" &
Clave.Text & "'", nc, adOpenStatic, adLockOptimistic,
adCmdText
75.


76.


77.

With rec
78.

If .RecordCount > 0 Then
79.

clav = .Fields("Clave")
80.

If Clave.Text = clav Then
81.

MsgBox "Bievenido al Sistema Stock " &
Space(2) & "- " & TxtLogin.Text, vbInformation, "Bienvenido
al Sistema"
82.

Unload Me
83.


84.

MDIForm1.Show
85.

End If
86.

Else
87.

MsgBox "Clave Incorrecta",
vbInformation, "Aviso..!!"
88.

TxtClave = ""
89.

TxtClave.SetFocus
90.


91.

End If
92.

End With
93.

rec.Close
94.

Set rec = Nothing
95.

End Sub