Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA style question 1

Status
Not open for further replies.

4281967

MIS
Oct 14, 2005
74
US
I have a form with several check boxes that will toggle depending on other controls/ Currently I have this:

Code:
Private Sub frmPaymentType_AfterUpdate()

        chJan.Value = 0
        chFeb.Value = 0
        chMar.Value = 0
        chApril.Value = 0
        chMay.Value = 0
        chJune.Value = 0
        chJuly.Value = 0
        chAug.Value = 0
        chSep.Value = 0
        chOct.Value = 0
        chNov.Value = 0
        chDec.Value = 0

End Sub

but is there a "cleaner" or more proficient way to code this?
 


Hi,

Are you saying that ALL the boxes could be either checked or unchecked?


Skip,

[glasses] [red]Be Advised![/red]
A wee deranged psychic may be runnin' around out there!
SMALL MEDUIM @ LARGE[tongue]
 


I think that I would use NUMBERS instead of TEXT (ch1, ch2, etc) and perform the intialization in a loop.

Code:
Private Sub InitializeMonthCheckBoxes()
  For i = 1 To 12
    UserForm1.Controls("ch" & i).Value = 0
  Next
End Sub
then call InitializeMonthCheckBoxes from the form AfterUpdate event


Skip,

[glasses] [red]Be Advised![/red]
A wee deranged psychic may be runnin' around out there!
SMALL MEDUIM @ LARGE[tongue]
 
thanks - that looks a lot better.

Can you help point me in the right direction with another question?

I have a frame frmPaymentType that has 3 options:

(PAYMENT TYPE) frmPaymentType
1=Quarterly
2=Monthly
3=Annually

using your example - I have all of my month check boxes selected if the user selects monthly on the frame. If they select anything else, it clears all the months:
Code:
Private Sub frmPaymentType_AfterUpdate() ' if quarterly or annual is selected clear all months
    For i = 1 To 12
    Forms!ACH_DataEntry.Controls("ch" & i).Value = 0
  Next

End Sub

Private Sub frmPaymentType_Click() ' if monthly is selected then select all months

    If frmPaymentType.Value = 2 Then
        For i = 1 To 12
            Forms!ACH_DataEntry.Controls("ch" & i).Value = 1
        Next
    End If
    
End Sub

my question:
I have a text box called txtStartDate. If for example the user put "11/15/05" in txtStartDate, and selected Quarterly (i.e. 1) on frmPaymentType it would check ch11, ch8, ch5 and ch2 to indicate which months are on this quarterly cycle (that starts depending on the month in txtStartDate.)

would it be easier if txtStartDate was a drop down? (the only valid dates are going to be the 1st or the 15th of any month)
 

I'd use the Calendar Control object to pop up (assign TRUE to visible property) on the Textbox Enter event, for instance.


Skip,

[glasses] [red]Be Advised![/red]
A wee deranged psychic may be runnin' around out there!
SMALL MEDUIM @ LARGE[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top