In Access 97, I have a form named frmEmpList with a list box that
contains the names of all our employees. I have a command button with
the following code in the OnClick event so the form will open showing
only the record of the employee selected from the list:
Dim varSelected As Variant
Dim strSQL As String
If IsNull(Me![EmpList]) Then
MsgBox "You must select an employee's name from the list.",
vbExclamation, "NOTE"
Else
For Each varSelected In Me!EmpList.Item sSelected
strSQL = strSQL & Me!EmpList.Item Data(varSelecte d) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL
End If
End If
What I'm trying to do is password protect frmVacationWeek s. I made a
Password form to prompt for a password with an unbound text box and
the following code in the OnClick event of a command button:
If Me!txtPassword = "password" Then
DoCmd.OpenForm "frmVacationWee ks"
DoCmd.Close acForm, "frmPasswor d"
Else
MsgBox "Incorrect Password", vbOKCancel
End If
Here's what happens - I have frmEmpList open, I select an employee
from the list, click the command button, and frmPassword opens. I
type in the correct password, frmPassword closes, and frmVacationWeek s
opens, but instead of showing the employee I selected from the list,
the first employee in the list shows. So, in effect, frmPassword
"interrupts " the code in the OnClick event of frmEmpList. How can I
modify the code so I can accomplish what I want to do?
By the way, I don't know a lot about VBA - someone helped me with the
code above. Thanks in advance for your help.
JD
contains the names of all our employees. I have a command button with
the following code in the OnClick event so the form will open showing
only the record of the employee selected from the list:
Dim varSelected As Variant
Dim strSQL As String
If IsNull(Me![EmpList]) Then
MsgBox "You must select an employee's name from the list.",
vbExclamation, "NOTE"
Else
For Each varSelected In Me!EmpList.Item sSelected
strSQL = strSQL & Me!EmpList.Item Data(varSelecte d) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[Employees].[EmployeeNumber] IN (" & Left(strSQL,
Len(strSQL) - 1) & ")"
DoCmd.OpenForm "frmVacationWee ks", acViewNormal, , strSQL
End If
End If
What I'm trying to do is password protect frmVacationWeek s. I made a
Password form to prompt for a password with an unbound text box and
the following code in the OnClick event of a command button:
If Me!txtPassword = "password" Then
DoCmd.OpenForm "frmVacationWee ks"
DoCmd.Close acForm, "frmPasswor d"
Else
MsgBox "Incorrect Password", vbOKCancel
End If
Here's what happens - I have frmEmpList open, I select an employee
from the list, click the command button, and frmPassword opens. I
type in the correct password, frmPassword closes, and frmVacationWeek s
opens, but instead of showing the employee I selected from the list,
the first employee in the list shows. So, in effect, frmPassword
"interrupts " the code in the OnClick event of frmEmpList. How can I
modify the code so I can accomplish what I want to do?
By the way, I don't know a lot about VBA - someone helped me with the
code above. Thanks in advance for your help.
JD
Comment