What am I doing Wrong?

G

Guest

I have the following code for my preview button. On my form i have an option
group and 2 unboud textboxes to enter dates for some of the information in
the option group would require one to enter...
So options 1,2,5,7 requires one to enter the date while 3,4,6 dont require
one to enter the date.
My code is doing the opposite, it opens the form or reports and a popup
messagebox says I need to enter the date. While 1,2,5,7 which require the
date dot do so Where am wrong?



Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_Preview_Click
' This procedure used in Preview_Click and Print_Click Sub procedures.
' Preview or print report selected in the ReportToPrint option group.

Dim DocName As String
Dim strControl As String
Const conIncomeRqst = 1
Const conPerComplRqst = 2
Const conVerStatusRqst = 5
Const conVerOutOfStd = 7

Const conWeeklyComplRqst = 3
Const conMonthlyComplRqst = 4
Const conYearlyComplRqst = 6


strControl = ""

If Me!Frame0.Value <> conWeeklyComplRqst <> conMonthlyComplRqst <>
conYearlyComplRqst Then
If IsDate(txtBeginDate) And IsDate(txtEndDate) Then
If CDate(txtEndDate) < CDate(txtBeginDate) Then
MsgBox "The ending date must be later than the beginning
date."
txtEndDate.SetFocus
Exit Sub
End If
Else
'MsgBox "Use valid dates for the beginning and ending date
values."
strControl = strControl & "Use valid date values for beginning
and ending" & vbCrLf
'Exit Sub
End If

End If
Select Case Me!Frame0
Case 1
DoCmd.OpenReport "New Requests", PrintMode
Case 2
DoCmd.OpenReport "Completed Requests", PrintMode
Case 3
DoCmd.OpenForm "Weekly Report", acNormal

Case 4
DoCmd.OpenReport "Monthly Report", PrintMode
Case 5
DoCmd.OpenReport "Status Report", PrintMode
Case 6
DoCmd.OpenReport "Year To Date", PrintMode
Case 7
DoCmd.OpenReport "Outstanding Report", PrintMode
End Select

If strControl <> "" Then
MsgBox "Following information required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
End If

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
Resume Exit_Preview_Click

End Sub

Private Sub Preview_Click()
' Preview selected report. This procedure uses the PrintReports
' Sub procedure defined in (General) section of this module.

PrintReports acPreview

End Sub
 
R

Ron Hinds

You're not using the And operator in your If...Then statement:

If Me!Frame0.Value <> conWeeklyComplRqst And Me!Frame0.Value <>
conMonthlyComplRqst And Me!Frame0.Value <> conYearlyComplRqst Then

Also, since you went to all the trouble of creating meaningful constants for
the values of your option buttons (excellent programming style BTW), why
aren't you using them in the Select...Case statement?

Select Case Me!Frame0
Case conIncomeRqst
DoCmd.OpenReport "New Requests", PrintMode
Case conPerComplRqst
DoCmd.OpenReport "Completed Requests", PrintMode
Case conWeeklyComplRqst
DoCmd.OpenForm "Weekly Report", acNormal
Case conMonthlyComplRqst
DoCmd.OpenReport "Monthly Report", PrintMode
Case conVerStatusRqst
DoCmd.OpenReport "Status Report", PrintMode
Case conYearlyComplRqst
DoCmd.OpenReport "Year To Date", PrintMode
Case conVerOutOfStd
DoCmd.OpenReport "Outstanding Report", PrintMode
End Select

It makes the code musch more readable (hence, more maintainable)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top