Command Button Visibility

G

Guest

I have a list box that when clicked fills a number in a text box (text24)

I then have code that looks at this text box number to determine which case
to use and then shows a command button that corresponds with the case. All
command buttons should not be visible until the corresponding case is
selected.

The last case is when the text box is empty. Then no command buttons should
show on the form. This is all working perfectly except for two buttons.
When the Text box is null, they still show up. They do disappear when
something is selected from the list box that corresponds to a case where they
should not be visible. I've copied and pasted from other cases to be sure I
don't have a typo. But, these last two buttons still show up when text24 is
empty. (cmdLoginAdmin and cmdLoginAaron) Here is the code for the last case:

Case 12 'No Criteria

Me!cmdLoginFull.Visible = False
Me!cmdLoginManagement.Visible = False
Me!cmdLoginOffice1.Visible = False
Me!cmdLoginOffice2.Visible = False
Me!cmdLoginForeman.Visible = False
Me!cmdLoginGeneral.Visible = False
Me!cmdLoginAdmin.Visible = False
Me!cmdLoginMaterialControl.Visible = False
Me!cmdLoginShop.Visible = False
Me!cmdLoginQuality.Visible = False
Me!cmdLoginAaron.Visible = False
 
G

Guest

What happen if you write istead of Case 12 ,
Try
Case Else

That will enter this code if no other case number is applied
 
G

Guest

I changed it to Case Else - with the same results. The two buttons are still
visible until the user selects a name from the combo box. Then they
disappear and the button corresponding to the selected name becomes visible.
The buttons are spelled correctly. I also have tried to add additional test
buttons and they too stay visible until a name is selected. So the "visible
- false" is working in the other Cases. But for some reason, not in the NULL
case. Any additional ideas?
 
E

e.mel

Null can give seemingly unusual reselts sometimes.
how are you using text24, maybe putting Nz() around it will help - this
will convert Null to "".

also a control cant be made invisible if it has the focus

but I doubt either of these is the problem. Can you post the code
where get to the various case numbers. ie how does text24=Null lead
to Case 12
 
G

Guest

Here is some of the code...hopefully the parts that will help you understand
what I'm doing.

=============
'THERE IS A 'CLICK' EVENT FOR EACH cmdBUTTON - THEY ARE IDENTICAL EXCEPT FOR
THE SUB NAME AND THE FORM EACH OPENS

Private Sub cmdLoginAaron_Click()

'Check to see if data is entered into the UserName list box

If IsNull(Me.Text24) Or Me.Text24 = "" Then
MsgBox "You must choose a User Name.", vbOKOnly, "Required Data"
Me.Text24.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Valid Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this
'matches value chosen in list box

If Me.txtPassword.Value = DLookup("EmpPassword", "tblEmployees", "[EmpID]="
& Me.Text24.Value & " And [EmpName]='" & Me.Text34.Value & "'") Then

lngMyEmpID = Me.Text24.Value


'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmAaron"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.",
vbCritical, "Restricted Access!"
Application.Quit
End If



End Sub
===============================
'TEXT24 IS A TEXT BOX THAT LOOKS UP THE EMPID IN A TABLE - THIS EQUALS THE
CASE NUMBER FOR EACH LOGON

Private Sub List31_Click()
Dim Code
Code = Me!Text24
Select Case Code

Case 11 'Aaron

Me!cmdLoginFull.Visible = False
Me!cmdLoginManagement.Visible = False
Me!cmdLoginOffice1.Visible = False
Me!cmdLoginOffice2.Visible = False
Me!cmdLoginForeman.Visible = False
Me!cmdLoginGeneral.Visible = False
Me!cmdLoginAdmin.Visible = False
Me!cmdLoginMaterialControl.Visible = False
Me!cmdLoginShop.Visible = False
Me!cmdLoginQuality.Visible = False
Me!cmdLoginAaron.Visible = True

Case Else 'No Criteria

Me!cmdLoginFull.Visible = True
Me!cmdLoginManagement.Visible = False
Me!cmdLoginOffice1.Visible = False
Me!cmdLoginOffice2.Visible = False
Me!cmdLoginForeman.Visible = False
Me!cmdLoginGeneral.Visible = False
Me!cmdLoginAdmin.Visible = False
Me!cmdLoginMaterialControl.Visible = False
Me!cmdLoginShop.Visible = False
Me!cmdLoginQuality.Visible = False
Me!cmdLoginAaron.Visible = False



End Select
[txtPassword].SetFocus

End Sub






============
 
G

Guest

I did get this to work for me. The two buttons that were visible needed to
have the visible property set to 'no'. However. I'd still like to
understand why Case 12 (or Case Else as I changed it to) would not work. If
text24 was empty it should have called case 12 or case else and made all the
buttons listed invisible...shouldn't it?

I'd like to try putting the nz function in the text24 code, but am getting a
code error. Here is the current code. Could you show me where I'd put the
Nz()?

=DLookUp("[EmpId]","qryLoginMenu1","[qryLoginMenu1]![EmpName] = '" &
[List31] & "'")

List31 is my list box of names to choose from. EmpId is the stored case
code .

Thank you.
 
E

e.mel

I'm pretty sure Nz() wouldnt fix it, but ordinarily you would use it
like this:
=Nz(DLookUp("[EmpId]","qryLoginMenu1","[qryLoginMenu1]![EmpName] = '" &
[List31] & "'"))

the Nz(var1, var2) functions checks var1 and if it is Null, returns 0
or "" or whatever var2 is. If DLookUp doesnt find anything it returns
Null and any password comparison will fail - which is what you want, so
it should stay how it is.


try this:

Case Else 'No Criteria

Beep
Beep
Beep

Me!cmdLoginFull.Visible = True
Me!cmdLoginManagement.Visible = False
Me!cmdLoginOffice1.Visible = False
Me!cmdLoginOffice2.Visible = False
Me!cmdLoginForeman.Visible = False
Me!cmdLoginGeneral.Visible = False
Me!cmdLoginAdmin.Visible = False
Me!cmdLoginMaterialControl.Visible = False
Me!cmdLoginShop.Visible = False
Me!cmdLoginQuality.Visible = False
Me!cmdLoginAaron.Visible = False
End Select

If you hear beeps then the case statement is working fine, and the
problem is with the buttons.

I'd try just using one button (cmdLogin) with two case statements. The
first case where you have it now and it would change cmdLogin.Caption
the other in the cmdLogin_OnClick that would call the code that was in
the OnClick events of the other buttons.

HTH

I did get this to work for me. The two buttons that were visible needed to
have the visible property set to 'no'. However. I'd still like to
understand why Case 12 (or Case Else as I changed it to) would not work. If
text24 was empty it should have called case 12 or case else and made all the
buttons listed invisible...shouldn't it?

I'd like to try putting the nz function in the text24 code, but am getting a
code error. Here is the current code. Could you show me where I'd put the
Nz()?

=DLookUp("[EmpId]","qryLoginMenu1","[qryLoginMenu1]![EmpName] = '" &
[List31] & "'")

List31 is my list box of names to choose from. EmpId is the stored case
code .

Thank you.

e.mel said:
Null can give seemingly unusual reselts sometimes.
how are you using text24, maybe putting Nz() around it will help - this
will convert Null to "".

also a control cant be made invisible if it has the focus

but I doubt either of these is the problem. Can you post the code
where get to the various case numbers. ie how does text24=Null lead
to Case 12
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top