Sorry, I should have included this in what I did. Yes, after each time I put
code back to the object, I compiled and then saved. The database itself has
a lot of code, some of it complicated, but the form in question is fairly
straight forward and simple. Code below in case there is something that I
have done wrong and/or there is a better way to write it. (I'm fairly an
Access novice)
The form is unbound - it enables/disables text boxes and combo boxes
depending the report selected (cmbReport) the data for this control comes
from tblReports which is a table that holds a list of reports (report name,
report title, various boolean fields that determine what data the report
needs to run - i.e. employee, fund, fiscalYear, fiscalMonth, from/to dates,
project, etc) the code also skips over fields that have been "auto filled"
(tab stops set, but these fields have the option of being filled in manually
or by selecting from other combo boxes - I skip over them if programmed to be
filled in.
START CODE
Option Compare Database
Option Explicit
Private Sub cmbFiscalYear_AfterUpdate()
If Not IsNull(Me.cmbFiscalYear) Then
Me.txtFromDate = Me.cmbFiscalYear.Column(1) 'set from date for
fiscal year select
Me.txtToDate = Me.cmbFiscalYear.Column(2) 'set to date for fiscal
year select
'set cursor in the next necessary field for data entry
If Me.cmbProject.Enabled Then
Me.cmbProject.SetFocus
Else
If Me.cmbJob.Enabled Then
Me.cmbJob.SetFocus
Else
If Me.cmbEmployee.Enabled Then
Me.cmbEmployee.SetFocus
Else
Me.cmdReport.SetFocus
End If
End If
End If
Else 'blank out the from/to dates
Me.txtFromDate = ""
Me.txtToDate = ""
End If
End Sub
Private Sub cmbFMonth_AfterUpdate()
If Not IsNull(Me.cmbFMonth) Then
Me.PayPeriod = "" 'blank out pay period box
Me.cmbFiscalYear = "" 'blank out fiscal year box
Me.txtFromDate = Me.cmbFMonth.Column(1) 'set from date with start
fiscal month date
Me.txtToDate = Me.cmbFMonth.Column(2) 'set to date with end fiscal
month date
Me.cmbFiscalYear = Me.cmbFMonth.Column(3) 'set fiscal year with
fiscal year of fiscal month selected
'set cursor in next necessary field for input
If Me.cmbFiscalYear.Enabled Then
Me.cmbFiscalYear.SetFocus
Else
If Me.cmbProject.Enabled Then
Me.cmbProject.SetFocus
Else
If Me.cmbJob.Enabled Then
Me.cmbJob.SetFocus
Else
If Me.cmbEmployee.Enabled Then
Me.cmbEmployee.SetFocus
Else
Me.cmdReport.SetFocus
End If
End If
End If
End If
Else 'blank out the from and to dates
Me.txtFromDate = ""
Me.txtToDate = ""
End If
End Sub
Private Sub cmbReport_AfterUpdate()
If Not IsNull(Me.cmbReport) Then
'Project CODE necessary for report to run
If Me.cmbReport.Column(2) = True Then
Me.cmbProject.Enabled = True
Else
Me.cmbProject.Enabled = False
End If
'employee necessary for report to run
If Me.cmbReport.Column(3) = True Then
Me.cmbEmployee.Enabled = True
Else
Me.cmbEmployee.Enabled = False
End If
'job code necessary for report to run
If Me.cmbReport.Column(4) = True Then
Me.cmbJob.Enabled = True
Else
Me.cmbJob.Enabled = False
End If
'from/to dates necessary for report to run
If Me.cmbReport.Column(5) = True Then
Me.cmbFMonth.Enabled = True
Me.PayPeriod.Enabled = True
Me.txtFromDate.Enabled = True
Me.txtToDate.Enabled = True
Else
Me.cmbFMonth.Enabled = False
Me.PayPeriod.Enabled = False
Me.txtFromDate.Enabled = False
Me.txtToDate.Enabled = False
End If
'fiscal year necessary for report to run
If Me.cmbReport.Column(6) = True Then
Me.cmbFiscalYear.Enabled = True
Else
Me.cmbFiscalYear.Enabled = False
End If
'fund necessary for report to run
If Me.cmbReport.Column(7) = True Then
Me.cmbFund.Enabled = True
Else
Me.cmbFund.Enabled = False
End If
'fiscal month necessary for report to run
If Me.cmbReport.Column(8) = True Then
Me.cmbFMonth.Enabled = True
Else
If Me.cmbReport.Column(5) = False Then
Me.cmbFMonth.Enabled = False
End If
End If
Else
Me.cmbProject.Enabled = False
Me.cmbEmployee.Enabled = False
Me.cmbJob.Enabled = False
Me.PayPeriod.Enabled = False
Me.txtFromDate.Enabled = False
Me.txtToDate.Enabled = False
Me.cmbFiscalYear.Enabled = False
Me.cmbFund.Enabled = False
Me.cmbFMonth.Enabled = False
End If
End Sub
Private Sub cmbReportCategory_AfterUpdate()
Me.cmbReport.Requery
Me.cmbReport.Enabled = True
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdReport_Click()
Dim runReport As Boolean
runReport = True
If IsNull(Me.cmbReport) Then
MsgBox "Select Report"
runReport = False
Else
If Me.cmbReport.Column(2) = True Then 'project code required
If IsNull(Me.cmbProject) Then
MsgBox "Report requires project code selection"
runReport = False
End If
End If
If Me.cmbReport.Column(3) = True Then 'employee required
If IsNull(Me.cmbEmployee) Then
MsgBox "Report requires employee selection"
runReport = False
End If
End If
If Me.cmbReport.Column(4) = True Then 'job code required
If IsNull(Me.cmbJob) Then
MsgBox "Report requires job code selection"
runReport = False
End If
End If
If Me.cmbReport.Column(5) = True Then 'from/to dates required
If IsNull(Me.txtFromDate) Then
MsgBox "Report requires from/to dates"
runReport = False
End If
If IsNull(Me.txtToDate) Then
MsgBox "Report requires from/to dates"
runReport = False
End If
End If
If Me.cmbReport.Column(6) = True Then 'fiscal year required
If Len(Trim(Me.cmbFiscalYear)) <> 4 Then
MsgBox "Report requires four digit fiscal year"
runReport = False
End If
End If
If Me.cmbReport.Column(7) = True Then 'fund required
If Me.cmbFund < 1 Or IsNull(Me.cmbFund) Then
MsgBox "Report requires fund"
runReport = False
End If
End If
If Me.cmbReport.Column(8) = True Then 'fiscal month required
If Me.cmbFMonth < 8 Or IsNull(Me.cmbFMonth) Then
MsgBox "Report requires valid fiscal month"
runReport = False
End If
End If
End If
If runReport = True Then
DoCmd.OpenReport Me.cmbReport, acViewPreview
End If
End Sub
Private Sub PayPeriod_AfterUpdate()
If Not IsNull(Me.PayPeriod) Then
Me.cmbFMonth = "" 'blank out fiscal month box
Me.cmbFiscalYear = "" 'blank out fiscal year box
Me.txtFromDate = Me.PayPeriod.Column(1) 'set from date with start
date from pay period
Me.txtToDate = Me.PayPeriod.Column(2) 'set to date with end date
from pay period
'set cursor in the next necessay field for data input
If Me.cmbFiscalYear.Enabled Then
Me.cmbFiscalYear.SetFocus
Else
If Me.cmbProject.Enabled Then
Me.cmbProject.SetFocus
Else
If Me.cmbJob.Enabled Then
Me.cmbJob.SetFocus
Else
If Me.cmbEmployee.Enabled Then
Me.cmbEmployee.SetFocus
Else
Me.cmdReport.SetFocus
End If
End If
End If
End If
Else 'blank out the from/to dates
Me.txtFromDate = ""
Me.txtToDate = ""
End If
End Sub
END CODE