S
StevePrefontaine
Hi,
I have a simple form with 3 Combo Boxes, all unbound. The first lists Months
(1 through 12), the second lists Years (2007 through 2010), and the third
lists Week Endings. The Week Ending combo box is populated using a select
query based on the selection in the other 2 combo boxes. I have simple
requeries on the after updates of the month and year combo boxes, which
successfully repopulate the week ending rows when month and/or year are
updated.
I have a button that generates a report based on this week ending. I now
would like to display an error message if the user clicks this button, but
has not make a selection from the week ending combo box. I have been able to
successfully do this if the user has not selected the week ending at any
previous point. I think this is because I've set the default value of week
ending to "". However, if the user has previously selected a week ending, and
then updated the month and/or year, the week ending is now blank, but no
error message is displayed. Here is a copy of the form code:
Private Sub cmbmonth_AfterUpdate()
Me.week_end.Requery
Me.week_end = ""
End Sub
Private Sub cmbyear_AfterUpdate()
Me.week_end.Requery
Me.week_end = ""
End Sub
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
DoCmd.Close
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
Private Sub Command1_Click()
On Error GoTo Err_Command1_Click
If Me.week_end = "" Then
x = MsgBox("Week Ending Required!", , "ERROR!")
Else
Dim stDocName As String
stDocName = "rptWeekly_Timesheets2"
DoCmd.OpenReport stDocName, acPreview
End If
Exit_Command1_Click:
Exit Sub
Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub
Keep in mind, I'm fairly new at VBA and not all of the code shown here was
done by me, but I have a basic understanding of it. Thank you.
I have a simple form with 3 Combo Boxes, all unbound. The first lists Months
(1 through 12), the second lists Years (2007 through 2010), and the third
lists Week Endings. The Week Ending combo box is populated using a select
query based on the selection in the other 2 combo boxes. I have simple
requeries on the after updates of the month and year combo boxes, which
successfully repopulate the week ending rows when month and/or year are
updated.
I have a button that generates a report based on this week ending. I now
would like to display an error message if the user clicks this button, but
has not make a selection from the week ending combo box. I have been able to
successfully do this if the user has not selected the week ending at any
previous point. I think this is because I've set the default value of week
ending to "". However, if the user has previously selected a week ending, and
then updated the month and/or year, the week ending is now blank, but no
error message is displayed. Here is a copy of the form code:
Private Sub cmbmonth_AfterUpdate()
Me.week_end.Requery
Me.week_end = ""
End Sub
Private Sub cmbyear_AfterUpdate()
Me.week_end.Requery
Me.week_end = ""
End Sub
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
DoCmd.Close
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
Private Sub Command1_Click()
On Error GoTo Err_Command1_Click
If Me.week_end = "" Then
x = MsgBox("Week Ending Required!", , "ERROR!")
Else
Dim stDocName As String
stDocName = "rptWeekly_Timesheets2"
DoCmd.OpenReport stDocName, acPreview
End If
Exit_Command1_Click:
Exit Sub
Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub
Keep in mind, I'm fairly new at VBA and not all of the code shown here was
done by me, but I have a basic understanding of it. Thank you.