Checkbox enable question

  • Thread starter Thread starter ryan.fitzpatrick3
  • Start date Start date
R

ryan.fitzpatrick3

I have a subform with freight components on it. I have it were if I
click a checkbox it'll run the following code where it'll disenable
the textbox selections until the checkbox is clicked "active" (enabled
or checked again). This works fine, but when I go to a new record, if
clicked "not active", the new record textbox remains disenabled. Is
there away for that to effect the direct record and not all records?
Thanks in advance.

Ryan


Private Sub FreightDivisionActive_Click()
If FreightDivisionActive = False Then
FreightAmount.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightAmount.Enabled = True
End If
If FreightDivisionActive = False Then
FreightLumpers.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightLumpers.Enabled = True
End If
If FreightDivisionActive = False Then
FreightFuelSurcharge.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightFuelSurcharge.Enabled = True
End If
If FreightDivisionActive = False Then
FreightZipCode.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightZipCode.Enabled = True
End If
If FreightDivisionActive = False Then
FreightTotalDelCosts.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightTotalDelCosts.Enabled = True
End If
If FreightDivisionActive = False Then
FreightCasesPerPallet.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightCasesPerPallet.Enabled = True
End If
If FreightDivisionActive = False Then
OptGroupFreight.Enabled = False
ElseIf FreightDivisionActive = True Then
OptGroupFreight.Enabled = True
End If
If FreightDivisionActive = False Then
FreightTLQuantity.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightTLQuantity.Enabled = True
End If
If FreightDivisionActive = False Then
FreighthalfLTLQuantity.Enabled = False
ElseIf FreightDivisionActive = True Then
FreighthalfLTLQuantity.Enabled = True
End If
If FreightDivisionActive = False Then
FreightthirdLTLQuantity.Enabled = False
ElseIf FreightDivisionActive = True Then
FreightthirdLTLQuantity.Enabled = True
End If
End Sub
 
The Click event of the check box is not the best place for your code. It
should be in the After Update event. There is also way more code than
necessary in the procedure.

You need to call this from two places. The Click event of
FreightDivisioinActive and from the Form Current event. That way, when you
navitage to a different record, it will set the controls for that record.


Private Sub SetDivsionActive()
With Me
.FreightAmount.Enabled = .FreightDivisionActive
.FreightLumpers.Enabled = .FreightDivisionActive
.FreightFuelSurcharge.Enabled = .FreightDivisionActive
.FreightZipCode.Enabled = .FreightDivisionActive
.FreightTotalDelCosts.Enabled = .FreightDivisionActive
.FreightCasesPerPallet.Enabled = .FreightDivisionActive
.OptGroupFreight.Enabled = .FreightDivisionActive
.FreightTLQuantity.Enabled = .FreightDivisionActive
.FreighthalfLTLQuantity.Enabled = .FreightDivisionActive
.FreightthirdLTLQuantity.Enabled = .FreightDivisionActive
End Sub
 
That did the trick, thanks Mr Hargis!

The Click event of the check box is not the best place for your code. It
should be in the After Update event. There is also way more code than
necessary in the procedure.

You need to call this from two places. The Click event of
FreightDivisioinActive and from the Form Current event. That way, when you
navitage to a different record, it will set the controls for that record.

Private Sub SetDivsionActive()
With Me
.FreightAmount.Enabled = .FreightDivisionActive
.FreightLumpers.Enabled = .FreightDivisionActive
.FreightFuelSurcharge.Enabled = .FreightDivisionActive
.FreightZipCode.Enabled = .FreightDivisionActive
.FreightTotalDelCosts.Enabled = .FreightDivisionActive
.FreightCasesPerPallet.Enabled = .FreightDivisionActive
.OptGroupFreight.Enabled = .FreightDivisionActive
.FreightTLQuantity.Enabled = .FreightDivisionActive
.FreighthalfLTLQuantity.Enabled = .FreightDivisionActive
.FreightthirdLTLQuantity.Enabled = .FreightDivisionActive
End Sub
 
I got a quick question for you. In the same form where I have the
enabled code, i have 3 checkboxes with 3 textboxes adjacent to them. I
have code where which ever checkbox I check the other two are
disabled. So i.e. in checkbox1 I click it checkbox2 and 3 are
disabled. So in textbox1 I type in the quantity, and this works, but I
can click checkbox2 or 3 and checkbox1 will be disabled even with the
quantity in it. How can I get it where if checkbox1 is clicked and
textbox1 has a number in it that you can't click anyother checkbox or
textbox until that quantity in textbox1 is deleted. Here is my code
thus far.

Private Sub Form_Current()
Select Case OptGroupFreight
Case 1
FreightTLQuantity.Enabled = True
FreighthalfLTLQuantity.Enabled = False
FreightthirdLTLQuantity.Enabled = False

Case 2
FreighthalfLTLQuantity.Enabled = True
FreightTLQuantity.Enabled = False
FreightthirdLTLQuantity.Enabled = False

Case 3
FreightthirdLTLQuantity.Enabled = True
FreightTLQuantity.Enabled = False
FreighthalfLTLQuantity.Enabled = False
End Select
End Sub

Thank you for your time.

Ryan
 
Back
Top