Solved Enable or Disable controls based on combo box (1 Viewer)

oxicottin

Learning by pecking away....
Local time
Today, 16:12
Joined
Jun 26, 2007
Messages
677
Hello, what am I doing incorrect? The example below needs to to this, If its a new record and its your first selection in cboProduct then run the test function.

Code:
  If IsNull(Me.cboProductID) Then
        Call test
    End If
    Exit Sub

Next lines are if there already is a selection and your changing it then give a message box to ask a question and yes do this else do that and call test either or to disable or enable controls based on your selection. What is happening is it works (as in enable/disable controls) on a new record and only on the first time something is selected in the combo box there after it does nothing.

Code:
Private Sub cboProductID_AfterUpdate()
'--------------------------------------------------------------------------------------------------
'  Clear controls if product is changed and requery length to get new sizes
'--------------------------------------------------------------------------------------------------

    If IsNull(Me.cboProductID) Then
        Call test
    End If
    Exit Sub

    If Not IsNull(Me.cboProductID) Then

        If MsgBox("Do you want to clear all data for this row?", vbYesNo + vbQuestion) = vbYes Then
            Me.txtSLegCS = Null
            Me.txtSLegNCS = Null
            Me.txtBeadCS = Null
            Me.txtBeadNCS = Null
            Me.txtPLegCS = Null
            Me.txtPLegNCS = Null
            Me.txtGapHigh = Null
            Me.txtGapLow = Null
            Me.txtAngle = Null

            Me.cboProductLength.SetFocus   ' Sets focus to Length combo box
            Me.txtProductLength = Null    ' Clears Text Box Product Length
            Me.cboProductLength.Requery  ' Requerys Product length to get new size

            Call test

        Else

            'Only clear product and length
            Me.cboProductLength.SetFocus   ' Sets focus to Length combo box
            Me.txtProductLength = Null    ' Clears Text Box Product Length
            Me.cboProductLength.Requery  ' Requerys Product length to get new size

            Call test

        End If
    End If
End Sub

Private Function test()

    With Forms!frm_ShiftDay!frm_ShiftMachinesRanSubform.Form!frm_MachineOutputSubForm.Form

        Select Case !cboProductID

        Case 21, 10
            Me.txtBeadCS.Enabled = False
            Me.txtBeadNCS.Enabled = False
            Me.txtAngle.Enabled = False
            Me.txtAngle = Null
            Me.txtBeadCS = Null
            Me.txtBeadNCS = Null
            Me.txtGapHigh.Enabled = True
            Me.txtGapLow.Enabled = True

        Case Else

            Me.txtBeadCS.Enabled = True
            Me.txtBeadNCS.Enabled = True
            Me.txtAngle.Enabled = True
            Me.txtGapHigh.Enabled = False
            Me.txtGapLow.Enabled = False
            Me.txtGapHigh = Null
            Me.txtGapLow = Null

        End Select
    End With
End Function
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:12
Joined
Feb 28, 2001
Messages
20,010
I'm gonna guess that the EXIT SUB in the middle of your sequence is your culprit. You MIGHT perhaps want that inside the IF block where it is only seen if you are executing the IF.
 

oxicottin

Learning by pecking away....
Local time
Today, 16:12
Joined
Jun 26, 2007
Messages
677
I still cant get it, I have it enabling and disabling through conditional formatting and that part is now working BUT I need to not have a message if cboProductID is a new entry and if im changing the selection in cboProduct then run the case select. I have been messing around with that for days and I just cant figure out the "If there was never a selection in cboProductID then do nothing"

Code:
Private Sub cboProductID_BeforeUpdate(Cancel As Integer)

If IsNull(Me.cboProductID.Value) Then
MsgBox "first entry do nothing"

Else

 '   Me.cboProductLength.SetFocus   ' Sets focus to Length combo box
 '   Me.txtProductLength = Null    ' Clears Text Box Product Length
  '  Me.cboProductLength.Requery  ' Requerys Product length to get new size

    'With Forms!frm_ShiftDay!frm_ShiftMachinesRanSubform.Form!frm_MachineOutputSubForm.Form
     With Forms!frm_MachineOutputSubForm
        Select Case !cboProductID

        Case 21, 10
        MsgBox "You selected a 21, 10 product"
        'Clear the bead for flex product
            Me.txtBeadCS = Null
            Me.txtBeadNCS = Null
        'Clear the angle for flex product
            Me.txtAngle = Null

        Case Else
        MsgBox "You selected a 1 product"
        'Clear Gap for all product except 21, 10 product
            Me.txtGapHigh = Null
            Me.txtGapLow = Null

        End Select
    End With
    End If
End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:12
Joined
Feb 19, 2013
Messages
13,006
your code is running in the control beforeupdate event - and at that point the value has not been assigned to the control, it will still be whatever it was before (i.e. it's oldvalue). Either use the afterupdate event or refer to the .text property in the before update event

Select Case !cboProductID.text
 

oxicottin

Learning by pecking away....
Local time
Today, 16:12
Joined
Jun 26, 2007
Messages
677
Ok, I got most of it to work except now I have to somehow add a messagebox

Code:
Private Sub cboProductID_AfterUpdate()
    
    If IsNull(Me.cboProductID.OldValue) Then
'Save selected value if there is one to save
        If Me.Dirty Then
            Me.Dirty = False
        End If
'Set focus, clear length and requery to show new sizes
        Me.cboProductLength.SetFocus
        Me.txtProductLength = Null
        Me.cboProductLength.Requery
        
    Else
        
       'With Forms!frm_ShiftDay!frm_ShiftMachinesRanSubform.Form!frm_MachineOutputSubForm.Form
        With Forms!frm_MachineOutputSubForm
            Select Case !cboProductID
                
            Case 21, 10
'Set focus, clear length and requery to show new sizes
                Me.cboProductLength.SetFocus
                Me.txtProductLength = Null
                Me.cboProductLength.Requery
'Clear the bead for flex product
                Me.txtBeadCS = Null
                Me.txtBeadNCS = Null
'Clear the angle for flex product
                Me.txtAngle = Null
                
            Case Else
'Set focus, clear length and requery to show new sizes
                Me.cboProductLength.SetFocus
                Me.txtProductLength = Null
                Me.cboProductLength.Requery
                
'Clear Gap for all product except 21, 10 product
                Me.txtGapHigh = Null
                Me.txtGapLow = Null
            End Select
        End With
    End If
End Sub
 

Users who are viewing this thread

Top Bottom