Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble with If then Loop based on Checkbox 1

Status
Not open for further replies.

splats

Technical User
Jan 2, 2003
131
Hello

Here's my code. Unfortunately, when the checkbox is clicked the code works, however, when I uncheck it, the code still tries to email the report rather than just show the report. Basically, the code is ignoring the fact that the checkbox's status is changed back to being unchecked. any input would be greatly appreciated. thank u

Private Sub CmdCostHrs_Click()
On Error GoTo Err_CmdCostHrs_Click

Dim stDocName As String

stDocName = "Costs and Hours Lost"
If IsNull(Me.ChkEmail) Then
DoCmd.OpenReport stDocName, acPreview

Else

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'DoCmd.OpenReport stDocName, acPreview
DoCmd.SendObject acSendReport, stDocName, acFormatSNP, , , , "Chart Statistics By Cost and Hours", , True

End If

Exit_CmdCostHrs_Click:
Exit Sub

Err_CmdCostHrs_Click:
MsgBox Err.Description
Resume Exit_CmdCostHrs_Click

End Sub
 
G'day tinat,

After activation a check box typically has value true or false, NOT Null (Which is an absense of a value - check the help file for more clarification, including tri-state)

To get around your issue set its default value to false, and then change this line of code:

Code:
If IsNull(Me.ChkEmail) Then

to

Code:
If Me!ChkEmail=false Then

or, "If not me!ChkEmail then" - it's your choice but either way you're checking for a true or false rather than a null :)

Have a great weekend,

JB
 
Thank you that works great. You made my evening!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top