i'm learning something new everyday... cstr()
well, it didn't work. i think i'm doing something wrong...
okay, i don't have the combo boxes linked to a table, instead i typed in the values i wanted at creation (using a wizard).
the first combo box is the month field. it has the months written out, ie January, February, etc.
the second combo box is the period. first period or second.
the third combo box is the year.
so... to take the month and the year i want for the combo box, i used the property .values. (ie cmbMonth.values)
the weird one is the period. i used an _afterupdate event to get it to put information in some variables, called starDate, endDate.
here's my code so far:
Option Compare Database
Dim begDate, lasDate As String
'update the sub form if user changes month in combo box
Private Sub cmbMth_AfterUpdate()
FilterMonth
End Sub
'update the subform if user changes the year in combo box
Private Sub cmbyear_afterupdate()
FilterMonth
End Sub
'the update for the pay period
'if first period, the beginning day is 1, and end date is 15
'if second period, beginning is 16 and end date is last date
'of month
Private Sub cmbPay_afterupdate()
If cmbPay.Value = "1-15" Then
begDate = 1
lasDate = 15
End If
If cmbPay.Value = "16-EOM" Then
begDate = 16
lasDate = String(1, Day(DateSerial(cmbYear.Value, cmbMth.Value + 1, 0))) 'this supposedly finds the last day
'of the month
End If
End Sub
'this section does not work; i get errors saying that there
'no value in the combo boxes.
Private Sub form_initialize()
cmbMth.Value = Month(Date)
begDate = 1
lasDate = 15
cmbYear.Value = year(Date)
End Sub
'the function that allows me to filter pay periods.
Function FilterMonth()
Dim PayPeriodStart, PayPeriodEnd As Date
Dim Store As String
PayPeriodStart = CStr(DateValue(cmbMth.Value + " " + begDate + ", " + cmbYear.Value))
PayPeriodEnd = CStr(DateValue(cmbMth.Value + " " + lasDate + ", " + cmbYear.Value))
Store = "SELECT * FROM [Calc Hours]where date > #" + PayPeriodStart + "# and date < #" + PayPeriodEnd + "#"
Set PayPInfo = [Calc Hours].createquerydef("PeriodQuery", Store)
[Calc Hours subform].Requery
End Function