Solved Enable or disable Combobox based on multiple conditions (1 Viewer)

allen675

Member
Local time
Today, 06:17
Joined
Jul 13, 2022
Messages
124
Hi,

Trying to get this to work but once I have entered info into all textboxes combo box still remains disabled. Where am I going wrong?

Code:
Private Sub Client_FN_AfterUpdate()
Call EnableClientStatusCombo
End Sub

Private Sub Phone_Call__1_AfterUpdate()
Call EnableClientStatusCombo
End Sub

Private Sub Client_SN_AfterUpdate()
Call EnableClientStatusCombo
End Sub

Private Sub Email_Address_AfterUpdate()
If Not IsNull(Me.Email_Address) Then
Me.Command16.Enabled = True
End If
Call EnableClientStatusCombo
End Sub

Private Sub Lead_Date_AfterUpdate()
Call EnableClientStatusCombo
End Sub

Private Sub Mobile_No_AfterUpdate()
Call EnableClientStatusCombo
If Not IsNull(Me.Mobile_No) Then
Me.Command17.Enabled = True
End If
End Sub

Sub EnableClientStatusCombo()
If Not IsNull(Me.Lead_Date) Then
If Not IsNull(Me.Client_FN) Then
If Not IsNull(Me.Client_SN) Then
If Not IsNull(Me.Mobile_No) Then
If Not IsNull(Me.Email_Address) Then
If Not IsNull(Me.Phone_Call__1) Then
Me.ClientStatus.Enabled = True
End If
End If
End If
End If
End If
End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:17
Joined
Oct 29, 2018
Messages
21,358
Hi. Probably easier to use Conditional Formatting, if you can.

Expression Is: IsNull([Lead_Date]+[Client_FN]+[Client_SN]+[Mobile_No]+[Email_Address]+[Phone_Call_1])
 

Minty

AWF VIP
Local time
Today, 06:17
Joined
Jul 26, 2013
Messages
10,355
I would suspect your combo's may not be Null?

Its also easier to loop around a set of controls with a tag value than have a million nested If statements.
So if your combo's all had Req in their tag property something like this (Note I use the Datasheet caption as it's something I can write a sensible field description in, if you change it to the ctl.name you'll get the jist)
Code:
Function ValidateRecs() As Boolean

    Dim sControls As String
    Dim ctl As Control
    Dim ctlColour As Long


    For Each ctl In Me.Controls
        If ctl.Tag = "Req" Then     'Reset the colours
            If ctl.BackColor = vbYellow Then
                ctlColour = VbWhite
                ctl.BackColor = ctlColour
            End If
            If ctl.Enabled Then
                'Debug.Print ctl.Name, ctl.value, ctl.Properties("DataSheetCaption")
                If IsNull(ctl.value) or Len(ctl.value & "") < 1 Then
                    sControls = sControls & ctl.Properties("DataSheetCaption") & vbCrLf
                    ctl.BackColor = vbYellow
                End If
            End If
        End If
    Next ctl
   
    ValidateRecs = True
    If Len(sControls & "") > 0 Then
        MsgBox "The following fields require data before the completion date can be entered;" & vbCrLf & vbCrLf & sControls, vbInformation + vbOKOnly, "Missing Data!"
        ValidateRecs = False
    End If
 

allen675

Member
Local time
Today, 06:17
Joined
Jul 13, 2022
Messages
124
Should I have said based on multiple textbox values?

I want one combobox enable if a selection of textboxes have any value
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:17
Joined
Oct 29, 2018
Messages
21,358
Should I have said based on multiple textbox values?

I want one combobox enable if a selection of textboxes have any value
Hi. In case I wasn't clear, I was saying use CF on the Combobox (if applicable).

Edit: Okay, just checked, Combobox can use CF
 

allen675

Member
Local time
Today, 06:17
Joined
Jul 13, 2022
Messages
124
Might seem like a silly question but how do you use conditional formatting to hide/make visible a combobox?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:17
Joined
Oct 29, 2018
Messages
21,358
Might seem like a silly question but how do you use conditional formatting to hide/make visible a combobox?
You can't; but, that's a different question than your original post where you said you wanted to enable or disable the Combobox - not hide it.
 

allen675

Member
Local time
Today, 06:17
Joined
Jul 13, 2022
Messages
124
Not to worry peep's, my original code works, however, I had a button that populates one of the text boxes with today's date and this wasn't activating the afterupdate event. So change design of form to allow for this. Thanks for your input 👍
 

Users who are viewing this thread

Top Bottom