Month buttons

rick roberts

Registered User.
Local time
Today, 18:29
Joined
Jan 22, 2003
Messages
160
i have a subform that contains data for each month of the year i want to place a set of buttons under the form for each month so that when a particular button is pressed the data for that month is displayed -- rather like a combo box would could anyone supply me with the vb code to do this --- also something that will catch the situation where no information has been supplied for that month - ie it doesnt exist for that particular record thanks in anticipation
 
Simple Software Solutions

I presume you are using this as a filtering option. Buttons can be quite large why not use a multi select list box and only populate the months of the year that you have data for.

On the assumption you are using Access as a back end then create a query that is grouped by month for a specfic year then use this to populate the listbox.

The user then highlights the months they want then they click a submit button to run a fiter on the underlying recordsource based on the selections made.

Make the first item in the list box = All periods



Code:
Dim Rs As Recordset

Set Rs = CurrentDb.OpenRecordset("QryPeriodsWithData")

Me.ListBox.Clear

If not Rs.EOF And Not Rs.BOF Then
    Me.Listbox.AddItem "All Periods"    
    Do Until Rs.EOF
        Me.ListBox.AddItem Rs("Period")
        Rs.MoveNext
    Loop
    Rs.Close
Else
    Me.ListBox.AddItem "Nothing to Select"
    Me.CmdSubmit.Enabled = False

End If

Code:
Sub CmdSubmit_Click()

   Here you would loop though all the selected items in the list 
   and concatenate all the month together with "," seperaters so you
   would end up with somthing like "January","February","March"

   Then use this within an In(StrPeriods) function as your where condition

   Finally do a refresh on your underlying data using the above.

End Sub

Above not tested and is for brevity only

CodeMaster::cool:
 
i already have something of that sort using a combo box but since the actual date is also in the same type of combo box (they just select which month the form attrributes to) i wanted something different so as not to confuse the user and cause them to enter the wrong box
 

Users who are viewing this thread

Back
Top Bottom