Solved disable/enable command button based 2 combobox value

Akai90

Member
Local time
Tomorrow, 06:33
Joined
Feb 8, 2022
Messages
67
hi,

based on title, i can disable command button if i have only use 1 combobox value. the is like

C#:
Private Sub Form_Current()
If Combo10.Value = "SEMENTARA" Then
Me.Command6.Enabled = True
Me.Command8.Enabled = True
Me.Command9.Enabled = False
Me.Command7.Enabled = False
Else
Me.Command9.Enabled = True
Me.Command7.Enabled = True
Me.Command6.Enabled = False
Me.Command8.Enabled = False
End If
End Sub

my question, how to combine with 2 or more combobox value

my example like form1
 

Attachments

Code:
Private Sub Combo10_AfterUpdate()
  EnableButtons
End Sub

Private Sub Combo16_AfterUpdate()
  EnableButtons
End Sub
Private sub Form_Current
 enableButtons
end sub

Private Sub EnableButtons
  Me.Command6.Enabled = (Combo10.Value = "Sementara" And Combo16.Value = "Something")
  Me.Command8.Enabled = (Combo10.Value = "Sementara" And Combo16.Value = "Something")
  Me.Command9.Enabled = Not (Combo10.Value = "Sementara" And Combo16.Value = "Something")
  Me.Command7.Enabled = Not (Combo10.Value = "Sementara" And Combo16.Value = "Something")
End Sub
 
Code:
Private Sub Combo10_AfterUpdate()
  EnableButtons
End Sub

Private Sub Combo16_AfterUpdate()
  EnableButtons
End Sub
Private sub Form_Current
enableButtons
end sub

Private Sub EnableButtons
  Me.Command6.Enabled = (Combo10.Value = "Sementara" And Combo16.Value = "Something")
  Me.Command8.Enabled = (Combo10.Value = "Sementara" And Combo16.Value = "Something")
  Me.Command9.Enabled = Not (Combo10.Value = "Sementara" And Combo16.Value = "Something")
  Me.Command7.Enabled = Not (Combo10.Value = "Sementara" And Combo16.Value = "Something")
End Sub
code work fine

only some value are not working

this my code on live access

C#:
Private Sub JENIS_PERMIT_AfterUpdate()
  EnableButtons
End Sub

Private Sub JenisInstitusi_AfterUpdate()
  EnableButtons
End Sub
Private Sub Form_Current()
EnableButtons
End Sub

Private Sub EnableButtons()
  Me.Command406.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "TADIKA SWASTA")
  Me.Command407.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "TADIKA SWASTA")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "PUSAT TUISYEN")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "PUSAT TUISYEN")
  Me.Command567.Enabled = (JenisInstitusi.Value = "PUSAT TUISYEN")
  Me.Command566.Enabled = (JenisInstitusi.Value = "PUSAT TUISYEN")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "SEKOLAH SWASTA (AKADEMIK)")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "SEKOLAH SWASTA (AKADEMIK")
  Me.Command567.Enabled = (JenisInstitusi.Value = "SEKOLAH SWASTA (AKADEMIK)")
  Me.Command566.Enabled = (JenisInstitusi.Value = "SEKOLAH SWASTA (AKADEMIK)")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "SEKOLAH SWASTA (AGAMA)")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "SEKOLAH SWASTA (AGAMA)")
  Me.Command567.Enabled = (JenisInstitusi.Value = "SEKOLAH SWASTA (AGAMA)")
  Me.Command566.Enabled = (JenisInstitusi.Value = "SEKOLAH SWASTA (AGAMA)")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "SEKOLAH SWASTA (PENDIDIKAN KHAS)")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "SEKOLAH SWASTA (PENDIDIKAN KHAS)")
  Me.Command567.Enabled = (JenisInstitusi.Value = "SEKOLAH SWASTA (PENDIDIKAN KHAS)")
  Me.Command566.Enabled = (JenisInstitusi.Value = "SEKOLAH SWASTA (PENDIDIKAN KHAS)")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "SEKOLAH MENENGAH PERSENDIRIAN CINA")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "SEKOLAH MENENGAH PERSENDIRIAN CINA")
  Me.Command567.Enabled = (JenisInstitusi.Value = "SEKOLAH MENENGAH PERSENDIRIAN CINA")
  Me.Command566.Enabled = (JenisInstitusi.Value = "SEKOLAH MENENGAH PERSENDIRIAN CINA")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "SEKOLAH ANTARABANGSA")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "SEKOLAH ANTARABANGSA")
  Me.Command567.Enabled = (JenisInstitusi.Value = "SEKOLAH ANTARABANGSA")
  Me.Command566.Enabled = (JenisInstitusi.Value = "SEKOLAH ANTARABANGSA")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "SEKOLAH EKSPATRIAT")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "SEKOLAH EKSPATRIAT")
  Me.Command567.Enabled = (JenisInstitusi.Value = "SEKOLAH EKSPATRIAT")
  Me.Command566.Enabled = (JenisInstitusi.Value = "SEKOLAH EKSPATRIAT")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "PUSAT LATIHAN / KEMAHIRAN")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "PUSAT LATIHAN / KEMAHIRAN")
  Me.Command567.Enabled = (JenisInstitusi.Value = "PUSAT LATIHAN / KEMAHIRAN")
  Me.Command566.Enabled = (JenisInstitusi.Value = "PUSAT LATIHAN / KEMAHIRAN")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "PUSAT BAHASA")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "PUSAT BAHASA")
  Me.Command567.Enabled = (JenisInstitusi.Value = "PUSAT BAHASA")
  Me.Command566.Enabled = (JenisInstitusi.Value = "PUSAT BAHASA")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "PUSAT KOMPUTER")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "PUSAT KOMPUTER")
  Me.Command567.Enabled = (JenisInstitusi.Value = "PUSAT KOMPUTER")
  Me.Command566.Enabled = (JenisInstitusi.Value = "PUSAT KOMPUTER")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "PUSAT BIMBINGAN / PEMBELAJARAN")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "PUSAT BIMBINGAN / PEMBELAJARAN")
  Me.Command567.Enabled = (JenisInstitusi.Value = "PUSAT BIMBINGAN / PEMBELAJARAN")
  Me.Command566.Enabled = (JenisInstitusi.Value = "PUSAT BIMBINGAN / PEMBELAJARAN")

  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA" And JenisInstitusi.Value = "PUSAT PERKEMBANGAN MINDA")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL" And JenisInstitusi.Value = "PUSAT PERKEMBANGAN MINDA")
  Me.Command567.Enabled = (JenisInstitusi.Value = "PUSAT PERKEMBANGAN MINDA")
  Me.Command566.Enabled = (JenisInstitusi.Value = "PUSAT PERKEMBANGAN MINDA")
End Sub

but only work on "tadika swasta"
command button by default i disable

anything wrong ?
 
Last edited:
anything wrong ?
Not necessarily wrong, but I would give those buttons more meaningful names to help understand the code better.

Just my 2 cents...
 
Not necessarily wrong, but I would give those buttons more meaningful names to help understand the code better.

Just my 2 cents...
problem solved i use if

like this
C#:
Private Sub JENIS_PERMIT_AfterUpdate()
  EnableButtons
End Sub

Private Sub JenisInstitusi_AfterUpdate()
  EnableButtons
End Sub
Private Sub Form_Current()
 EnableButtons
End Sub

Private Sub EnableButtons()

If Me.JenisInstitusi.Value = "TADIKA SWASTA" Then
  Me.Command406.Enabled = (JENIS_PERMIT.Value = "SEMENTARA")
  Me.Command407.Enabled = (JENIS_PERMIT.Value = "KEKAL")
  Else
 
  Me.Command223.Enabled = (JENIS_PERMIT.Value = "SEMENTARA")
  Me.Command350.Enabled = (JENIS_PERMIT.Value = "KEKAL")
  Me.Command567.Enabled = True
  Me.Command566.Enabled = True
End If

End Sub

thanks for help and code
 
You have buttons with numbers like that? :(
 
At some point, your form is going to break. Access has a hard limit as to the number of controls a form may have. Either you are constantly adding/deleting objects to one form or you actually have hundreds of controls on one form. Access does not forget so even if you have 2 controls left on the form, if you get to the limit because over time, you have added/deleted hundreds of controls, the form breaks. There has to be better ways of doing this. Also as theDBguy said, you really need to use better names.
 
@Pat Hartman I don't think OP has that many buttons :), more creating deleting. :)

My thoughts were 'How on earth is anyone meant to know what button does what?' :(
 
I agree but the point is whether it is adding/deleting or just adding, the form will break when the magic number is reached even if there are only two controls left on the form:) Access never forgets:)
 
I agree but the point is whether it is adding/deleting or just adding, the form will break when the magic number is reached even if there are only two controls left on the form:) Access never forgets:)
I didn't know that. ? But then again, I have never gone that high with controls. :)
 
I tested this in the below thread and was able to add about 1040 controls. The number includes deleted controls. So you can add then delete in a loop up to about 1040. after that you can add no more. The MS website shows 754, but that is not current.

So this is one reason I discourage any attempt to make dynamic forms where you are adding controls on the fly. Even though you may only add a few each time, it remembers.
 
Thanks for verifying my statement Maj. I also didn't realize that the documentation was wrong. So thanks for that too:)
 
I tested this in the below thread and was able to add about 1040 controls. The number includes deleted controls. So you can add then delete in a loop up to about 1040. after that you can add no more. The MS website shows 754, but that is not current.

So this is one reason I discourage any attempt to make dynamic forms where you are adding controls on the fly. Even though you may only add a few each time, it remembers.
@MajP
That might well be with your version of Access?
I am on 2007, if you send me your code, I will advise at what 2007 balks at :)
 

Users who are viewing this thread

Back
Top Bottom