R
raylopez99
What am I doing wrong with DLookup below? I think the solution lies
in how to access a field in another main form from a main form.
I keep getting an error saying "You Canceled the Previous Operation".
The key: DCount below--see the line after "'''''''''''''''''''''''
DCOUNT HERE ''''''''''''''''''''''''''''''''''"--I am trying to
reference a field "LoginUserPassword" found in another table called
"TblLoginUser". As you can see for yourself below, this field, on the
RHS of the "=" sign, is being compared to the LHS that comes from a
form where the below _Click() event resides, and comparing a form's
field (bound to another table) called "LogPasswordEntered" to
"LoginUserPassword"; if they are equal, then we open a form called
"FrmSwitchboard"; if not, we exit (please ignore the MsgBox stuff,
which is just there to debug).
This code looks standard / benign/ generic to me, and is adapted
from: http://chazelleconsulting.com/Resources/Database/Password-protect_a_form.htm
In short, how to reference (using the "=" sign) a bound field found in
another table? See also this post, which implies it's tougher than a
simple reference (or so it seems): http://blog.vishalon.net/Post/50.aspx
RL
Private Sub CmdLogin_Click()
''''''''''' _Click() is an event associated with a button on a form,
the same form having the field "LogPasswordEntered"
On Error GoTo Err_CmdLogin_Click
'''''''''''''''''''''''''''''''''
Dim msg220 As String
Dim title220 As String
'Dim style As MsgBoxStyle
Dim response220
msg220 = LogLoginUserLoginName.Value & LogPasswordEntered.Value
title220 = "Data Initial."
response220 = MsgBox(msg220, 0, title220) 'o is OK only button
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim VarXS As String
VarXS = CStr(LogLoginUserLoginName)
''''''''''''''''''''''' DCOUNT HERE ''''''''''''''''''''''''''''''''''
If (VarXS = DLookup("[LoginUserLoginName]", "TblLoginUser",
"[LoginUserPassword]= Me.LogPasswordEntered")) Then
DoCmd.OpenForm "FrmSwitchboard"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Not IsNull(LogLoginUserLoginName) Then
'''''''''''''''''''''''''''''''''''''''''''''
Dim msg221 As String
Dim title221 As String
'Dim style As MsgBoxStyle
Dim response221
msg221 = LogLoginUserLoginName.Value
title221 = "Data True ' Define title."
response221 = MsgBox(msg221, 0, title221) 'o is OK only button
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim msg222 As String
Dim title222 As String
'Dim style As MsgBoxStyle
Dim response222
msg222 = "LogLoginUserLoginName.Value is NULL!"
title222 = "Data False ' Define title."
response222 = MsgBox(msg222, 0, title222) 'o is OK only button
''''''''''''''''''''''''''''''''''''''''''''''''''''''
End If
Me.LogProblem = -1
DoCmd.Quit
End If
'Forms.frmLogin.Visible = False
Exit_CmdLogin_Click:
Exit Sub
Err_CmdLogin_Click:
MsgBox Err.Description
Resume Exit_CmdLogin_Click
End Sub
in how to access a field in another main form from a main form.
I keep getting an error saying "You Canceled the Previous Operation".
The key: DCount below--see the line after "'''''''''''''''''''''''
DCOUNT HERE ''''''''''''''''''''''''''''''''''"--I am trying to
reference a field "LoginUserPassword" found in another table called
"TblLoginUser". As you can see for yourself below, this field, on the
RHS of the "=" sign, is being compared to the LHS that comes from a
form where the below _Click() event resides, and comparing a form's
field (bound to another table) called "LogPasswordEntered" to
"LoginUserPassword"; if they are equal, then we open a form called
"FrmSwitchboard"; if not, we exit (please ignore the MsgBox stuff,
which is just there to debug).
This code looks standard / benign/ generic to me, and is adapted
from: http://chazelleconsulting.com/Resources/Database/Password-protect_a_form.htm
In short, how to reference (using the "=" sign) a bound field found in
another table? See also this post, which implies it's tougher than a
simple reference (or so it seems): http://blog.vishalon.net/Post/50.aspx
RL
Private Sub CmdLogin_Click()
''''''''''' _Click() is an event associated with a button on a form,
the same form having the field "LogPasswordEntered"
On Error GoTo Err_CmdLogin_Click
'''''''''''''''''''''''''''''''''
Dim msg220 As String
Dim title220 As String
'Dim style As MsgBoxStyle
Dim response220
msg220 = LogLoginUserLoginName.Value & LogPasswordEntered.Value
title220 = "Data Initial."
response220 = MsgBox(msg220, 0, title220) 'o is OK only button
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim VarXS As String
VarXS = CStr(LogLoginUserLoginName)
''''''''''''''''''''''' DCOUNT HERE ''''''''''''''''''''''''''''''''''
If (VarXS = DLookup("[LoginUserLoginName]", "TblLoginUser",
"[LoginUserPassword]= Me.LogPasswordEntered")) Then
DoCmd.OpenForm "FrmSwitchboard"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Not IsNull(LogLoginUserLoginName) Then
'''''''''''''''''''''''''''''''''''''''''''''
Dim msg221 As String
Dim title221 As String
'Dim style As MsgBoxStyle
Dim response221
msg221 = LogLoginUserLoginName.Value
title221 = "Data True ' Define title."
response221 = MsgBox(msg221, 0, title221) 'o is OK only button
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim msg222 As String
Dim title222 As String
'Dim style As MsgBoxStyle
Dim response222
msg222 = "LogLoginUserLoginName.Value is NULL!"
title222 = "Data False ' Define title."
response222 = MsgBox(msg222, 0, title222) 'o is OK only button
''''''''''''''''''''''''''''''''''''''''''''''''''''''
End If
Me.LogProblem = -1
DoCmd.Quit
End If
'Forms.frmLogin.Visible = False
Exit_CmdLogin_Click:
Exit Sub
Err_CmdLogin_Click:
MsgBox Err.Description
Resume Exit_CmdLogin_Click
End Sub