Login Session code don't run

Beatles96

New member
Local time
Yesterday, 17:56
Joined
Oct 7, 2014
Messages
3
Hi, where I am going wrong with this. I currently have it in a model labeled sessions and it is not saving anything. Am I supposed to call the session with cmdAceptar_on Click? I am not sure how to do this if I do have to. Where else might I be going wrong in my code?

see code on button :

Private Sub cmdAceptar_Click()
On Error GoTo Err:
'variable local para nombre y clave de usuario
Dim NOMUSU As String
Dim CVEUSU As String
'Asignar el valor de los controles a las variables locales
NOMUSU = UCase(Nz(Me.TxtNOMBRE_USUARIO.Value, ""))
CVEUSU = UCase(Nz(Me.TxtCLAVE_USUARIO.Value, ""))
If IsEmpty(NOMUSU) Or IsEmpty(CVEUSU) Then
MsgBox "Datos Incompletos...", vbOKOnly + vbCritical, "Imposible Ingresar!!"
Else
'Buscar Usuario con los datos ingresados
If ExisteUsuario(NOMUSU, CVEUSU) = True Then
MsgBox "Bienvenido al Sistema", vbOKOnly + vbInformation, "Acceso Exitoso"
DoCmd.Close 'Cerrar ventana de Acceso
'Codigo para entrar al sistema
DoCmd.Form_Open "Menu_P", acNormal
Else
NumIntento = NumIntento + 1
If NumIntento <= 2 Then
MsgBox "Usuario o Clave incorrecta", vbCritical + vbOKOnly, "Acceso Denegado"
Me.TxtNOMBRE_USUARIO.Value = ""
Me.TxtCLAVE_USUARIO.Value = ""
Me.TxtNOMBRE_USUARIO.SetFocus
Else
MsgBox "Demasiados Intentos, el Sistema se cerrara!", vbCritical + vbOKOnly, "Fallas de Acceso"
DoCmd.Quit
End If

Exit Sub
Err:
MsgBox Err.Description
End Sub

Public Function ExisteUsuario(strNomUsuario As String, strCveUsuario As String) As Boolean
On Error GoTo us_err
Dim Rst As DAO.Recordset
Dim SQL As String
SQL = "SELECT * FROM [USUARIOS] US WHERE US.[NOMBRE_USUARIO]='" & strNomUsuario & "' AND US.[CLAVE_USUARIO]='" & strCveUsuario & "'"
Set Rst = CurrentDb.OpenRecordset(SQL)
If Rst.BOF And Rst.EOF Then
ExisteUsuario = False
Else
ExisteUsuario = True
'Se Inicializaran las variables de Sesion
xNOMBRE_USUARIO = Rst!NOMBRE_USUARIO
xCLAVE_USUARIO = Rst!CLAVE_USUARIO
xNOMBRE = Rst!NOMBRE
xAPELLIDO_PATERNO = Rst!APELLIDO_PATERNO
xAPELLIDO_MATERNO = Rst!APELLIDO_MATERNO
xADMINISTRAR = Rst!ADMINISTRAR
xREPORTES = Rst!REPORTES
xFASTENAL = Rst!FASTENAL
xINSPECCION = Rst!Inspeccion
xECN = Rst!ECN
xNCMR = Rst!NCMR
End If
Rst.Close
Set Rst = Nothing
Exit Function
us_err:
MsgBox Err.Description
End Function
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err:
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunMacro "OCULTAR_PANEL"
'Fijar Icono
Dim intX As Integer
Const DB_Text As Long = 10
intX = AddAppProperty("AppTitle", DB_Text, "Incoming DB Kevin W1-Mod")
intX = AddAppProperty("AppIcon", DB_Text, CurrentProject.Path & "\img\apple-ico.ico")
CurrentDb.Properties("UseAppIconForFrmRpt") = 1
Application.RefreshTitleBar
Exit Sub
Err:
MsgBox Err.Description
End Sub
Function AddAppProperty(strName As String, _
varType As Variant, varValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo AddProp_Err
dbs.Properties(strName) = varValue
AddAppProperty = True
AddProp_Bye:
Exit Function
AddProp_Err:
If Err = conPropNotFoundError Then
Set prp = dbs.CreateProperty(strName, varType, varValue)
dbs.Properties.Append prp
Resume
Else
AddAppProperty = False
Resume AddProp_Bye
End If
End Function


what would be the module VBA Session for the login form first start?
 

Attachments

What you've posted here is a mixture Functions and Private Subs. You will experience trouble if you've pasted all this code into a module.
Functions should be saved in Modules and can be called from anywhere within your project, but Private Subs can only be accessed from the associated object which I guess is your form, if you have pasted this Sub code into a module, it can't be accessed.

David
 
Hi, thanks David.

no, this code is an button cmdAceptar_Click().

Code in Module VBA called"Session" is:

Option Compare Database
Option Explicit
'VARIABLES DE SESION
'SE NOMBRARAN IGUAL TAL COMO EN EL DISEÑO DE LAS TABLAS, PERO CON EL PREFIJO "x"
'PARA IDENTIFICARLAS COMO VARIABLES DE SESION
'----------- DATOS DE USUARIO-----------
Public xNOMBRE_USUARIO As String
Public xCLAVE_USUARIO As String
Public xNOMBRE As String
Public xAPELLIDO_MATERNO As String
Public xAPELLIDO_PATERNO As String
Public xMenu_P As Boolean
Public xADMINISTRAR As Boolean
Public xREPORTES As Boolean
Public xNCMRs As Boolean
Public xECNs As Boolean
Public xFASTENAL As Boolean
Public xINSPECCION As Boolean
'---------------------------------------
Public NumIntento As Byte




David,
could you sent my project db?

thanks in advance!
 
Functions should be saved in Modules and can be called from anywhere within your project,

Not necessarily. Public functions in object modules become a Method of the object.

BTW Beatles, your question would be much easier to read if you posted your code inside code tags and indented it.
 

Users who are viewing this thread

Back
Top Bottom