Hi all,
I´m really new in using access so while I´m starting reading short documents, o tutorials on access I tried to create a form that recognazes two kind of users and when you log in it shows a different form, reading and seen videos I type something like this (code below) but when run in a click on a buttom it says....
Compile Error: Variable not defined:
In this forum read that you must declare global variables on a Module, so I added this on a Modele Called Modeule1 but also doesn´t work.
Option Compare Database
Option Explicit
Public strAdmin As String
Public strUsuar As String
Usuar and Admin are the form that will appear when login as a usuary or Administrator.
Can anyone help me a little? Thanks in advance.
Option Compare Database
Option Explicit
Dim NumIntentos As Integer
Private Sub CmdEntrar_Click()
Dim auxContraseña As String
'Comprobamos que hay datos en las cajas de texto
If Nz(Me.TxtLogin.Value, "") = "" Then
MsgBox "Seleccione un nombre de usuario de la lista para acceder", vbInformation, "ATENCION"
Me.TxtLogin.SetFocus
ElseIf Nz(Me.TxtPassword.Value, "") = "" Then
MsgBox "Introduzca la contraseña del usuario seleccionado", vbInformation, "ATENCION"
Me.TxtPassword.SetFocus
Else
'If Nz(DLookup("Password", "Usuarios", "Id_usuario" & Me![TxtLogin]), "") <> "" Then
If Nz(DLookup("Password", "Usuarios", "Id_usuario=" & Me![TxtLogin]), "") <> "" Then
auxContraseña = DLookup("Password", "Usuarios", "Id_usuario=" & Me![TxtLogin])
End If
If auxContraseña <> Me.TxtPassword.Value Then
If NumIntentos > 1 Then
NumIntentos = NumIntentos - 1
MsgBox "La contraseña introducida es incorrecta" & vbCrLf & _
" Le quedan " & NumIntentos & "intentos" & vbCrLf & vbCrLf & _
"Por favor, introduzca otra", vbExclamation, "INTRODUCCION INCORRECTA"
Me.TxtPassword.Value = ""
Me.TxtPassword.SetFocus
Else
MsgBox "Ha superado el número de intentos", vbCritical, "...ADIOS"
DoCmd.Close acForm, Me.Name 'y cerramos el de acceso
End If
Else
If DLookup("Id_acceso", "Usuarios", "Id_usuario=" & Me![TxtLogin]) = 1 Then
MsgBox "Ha entrado el Administrador, mostramos todas las tablas", vbInformation, "BIENVENIDO ADMINISTRADOR"
Call Admin
Else
MsgBox "Ha entrado un usuario, ocultamos todas las tablas", vbInformation, "BIENVENIDO USUARIO"
Call Usuar
End If
'DoCmd.OpenForm stDocName, , , stLinkCriteria 'Abrimos el formulario correspondiente
DoCmd.Close acForm, Me.Name 'y cerramos el de acceso
End If
End If
End Sub
Function Admin()
On Error GoTo Admin_Err
DoCmd.OpenForm "Admin", acNormal, "", "", , acNormal
Admin_Exit:
Exit Function
Admin_Err:
MsgBox Error$
Rsume Admin_Exit
End Function
Function Usuar()
On Error GoTo Admin_Err
DoCmd.OpenForm "usuario", acNormal, "", "", , acNormal
Usuar_Exit:
Exit Function
Admin_Err:
MsgBox Error$
Rsume Usuar_Exit
End Function
I´m really new in using access so while I´m starting reading short documents, o tutorials on access I tried to create a form that recognazes two kind of users and when you log in it shows a different form, reading and seen videos I type something like this (code below) but when run in a click on a buttom it says....
Compile Error: Variable not defined:
In this forum read that you must declare global variables on a Module, so I added this on a Modele Called Modeule1 but also doesn´t work.
Option Compare Database
Option Explicit
Public strAdmin As String
Public strUsuar As String
Usuar and Admin are the form that will appear when login as a usuary or Administrator.
Can anyone help me a little? Thanks in advance.
Option Compare Database
Option Explicit
Dim NumIntentos As Integer
Private Sub CmdEntrar_Click()
Dim auxContraseña As String
'Comprobamos que hay datos en las cajas de texto
If Nz(Me.TxtLogin.Value, "") = "" Then
MsgBox "Seleccione un nombre de usuario de la lista para acceder", vbInformation, "ATENCION"
Me.TxtLogin.SetFocus
ElseIf Nz(Me.TxtPassword.Value, "") = "" Then
MsgBox "Introduzca la contraseña del usuario seleccionado", vbInformation, "ATENCION"
Me.TxtPassword.SetFocus
Else
'If Nz(DLookup("Password", "Usuarios", "Id_usuario" & Me![TxtLogin]), "") <> "" Then
If Nz(DLookup("Password", "Usuarios", "Id_usuario=" & Me![TxtLogin]), "") <> "" Then
auxContraseña = DLookup("Password", "Usuarios", "Id_usuario=" & Me![TxtLogin])
End If
If auxContraseña <> Me.TxtPassword.Value Then
If NumIntentos > 1 Then
NumIntentos = NumIntentos - 1
MsgBox "La contraseña introducida es incorrecta" & vbCrLf & _
" Le quedan " & NumIntentos & "intentos" & vbCrLf & vbCrLf & _
"Por favor, introduzca otra", vbExclamation, "INTRODUCCION INCORRECTA"
Me.TxtPassword.Value = ""
Me.TxtPassword.SetFocus
Else
MsgBox "Ha superado el número de intentos", vbCritical, "...ADIOS"
DoCmd.Close acForm, Me.Name 'y cerramos el de acceso
End If
Else
If DLookup("Id_acceso", "Usuarios", "Id_usuario=" & Me![TxtLogin]) = 1 Then
MsgBox "Ha entrado el Administrador, mostramos todas las tablas", vbInformation, "BIENVENIDO ADMINISTRADOR"
Call Admin
Else
MsgBox "Ha entrado un usuario, ocultamos todas las tablas", vbInformation, "BIENVENIDO USUARIO"
Call Usuar
End If
'DoCmd.OpenForm stDocName, , , stLinkCriteria 'Abrimos el formulario correspondiente
DoCmd.Close acForm, Me.Name 'y cerramos el de acceso
End If
End If
End Sub
Function Admin()
On Error GoTo Admin_Err
DoCmd.OpenForm "Admin", acNormal, "", "", , acNormal
Admin_Exit:
Exit Function
Admin_Err:
MsgBox Error$
Rsume Admin_Exit
End Function
Function Usuar()
On Error GoTo Admin_Err
DoCmd.OpenForm "usuario", acNormal, "", "", , acNormal
Usuar_Exit:
Exit Function
Admin_Err:
MsgBox Error$
Rsume Usuar_Exit
End Function