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?
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?