Solved Enabling a button, only if Comboboxes have values (1 Viewer)

OnePoint Consulting

New member
Local time
Today, 23:15
Joined
Apr 2, 2020
Messages
15
Hi Guys,

i'm trying to get a command button to be disabled in it's default state and only to be enabled when the user enters values (text and Dates) into combo and text boxes.

i've tried following code in VBA but i haven't been successful yet… could someone help out?

Thanks in advance =)

Code:
private sub Command1_Click()
    if Me.ComboFirma.Value = Null Then
    Me.Command1.Enabled = False
    Else
    Me.Command1.Enabled = True
    End if
 
    'Run Query
    DoCmd.OpenQuery "Query1"
End Sub

The remaning Combo and text boxes are missing in the code, since i don't/wouldn't know how to "add" them…
 

Attachments

  • access.jpg
    access.jpg
    79.3 KB · Views: 78

Minty

AWF VIP
Local time
Today, 22:15
Joined
Jul 26, 2013
Messages
10,371
You would need to add code to the after update event of the other controls, not the one you are trying to click, that would check their values.
So save the form with the cmd button disabled initially, then do something like

Private comboFirma_AfterUpdate()

Me.Command1.Enabled = False
If Not IsNull(Me.ComboFirma) and Not IsNull(Me.ComboOther) Then
Me.Command1.Enabled = True
End If

You'd need to do the same for your other combo assuming they both need a value.
This assumes your combos are text values and not storing numbers in which case check for 0 not null.
 

OnePoint Consulting

New member
Local time
Today, 23:15
Joined
Apr 2, 2020
Messages
15
You would need to add code to the after update event of the other controls, not the one you are trying to click, that would check their values.
So save the form with the cmd button disabled initially, then do something like

Private comboFirma_AfterUpdate()

Me.Command1.Enabled = False
If Not IsNull(Me.ComboFirma) and Not IsNull(Me.ComboOther) Then
Me.Command1.Enabled = True
End If

You'd need to do the same for your other combo assuming they both need a value.
This assumes your combos are text values and not storing numbers in which case check for 0 not null.
Thank you Minty =)

i've tried it and it seems to work, but not perfectly yet… The textbox values are numbers and you said something about "Checking for 0" in this case... is this the error? and if yes, how do i implement this?

ohh, and do you know what i'd need to add, if i'd want the command box to give me a "Disabled" look, before being enabled?
 

OnePoint Consulting

New member
Local time
Today, 23:15
Joined
Apr 2, 2020
Messages
15
okay, so i've also added the code to the "form current event" and the only box that isn't behaving like the rest is the second Textbox. It's the only one that'll enable the command button even if the other boxes have no values in them… all the other combo/text boxes work

This is the code is used on all the combo and text boxes and in "form current event"

Code:
    Me.Befehl53.Enabled = False
    If Not IsNull(Me.ComboFirmaSt) And Not IsNull(Me.ComboStatusSt) And Not IsNull(Me.TextZeitraumBis) And Not IsNull(Me.TextZeitraumVon) Then
    Me.Befehl53.Enabled = True
End If
 

Minty

AWF VIP
Local time
Today, 22:15
Joined
Jul 26, 2013
Messages
10,371
As mentioned if your combo's bound value is a number then when it has nothing selected its value is 0 not null. So assuming it's ComboStatusSt then change the code to


Code:
   Me.Befehl53.Enabled = False

   If Not IsNull(Me.ComboFirmaSt) And Me.ComboStatusSt <> 0 And Not IsNull(Me.TextZeitraumBis) And Not IsNull(Me.TextZeitraumVon) Then

          Me.Befehl53.Enabled = True

   End If
 

OnePoint Consulting

New member
Local time
Today, 23:15
Joined
Apr 2, 2020
Messages
15
Thanks again Minty =D

I understood the part with the "value is a number", i just didn't know how to type it in... I have no actualy knowledge of coding, it's been YouTube tutorials and online forums since i started working on this project.

But it all works perfectly now, soo thanks a lot and I hope you guys all have a great day!!
 

Minty

AWF VIP
Local time
Today, 22:15
Joined
Jul 26, 2013
Messages
10,371
Glad you have it working, we pretty much all started that way or with books BI (Before Internet !)
Guten Tag!
 

Users who are viewing this thread

Top Bottom