Compile Error: Variable not defined

narillos

New member
Local time
Today, 04:24
Joined
May 14, 2013
Messages
7
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
 
Where is the error? I don't see you using either of those variables elsewhere.
 
Good catch! Same in the other function.
 
Hi I attach the database I´m trying to use.

Can you check why it doesn´t put the user on "Bitacora" -(historical), on the other side I see it should put the "enter" usuary but how should I add thar also put the exit?

I hope you can help me Iñ m getting crazy....
 

Attachments

I'm not clear on the question. The Ingreso form is bound to the Bitacora table, but as you have it, it will always edit the first record. I suppose you could change the data entry property of the form to Yes, but I'd probably use code to add the record after a successful login.
 

Users who are viewing this thread

Back
Top Bottom