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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ACCESS VBA Question

Status
Not open for further replies.

calihiker

Technical User
Jun 13, 2003
96
US
I have a form that collects parameters to be used in a report. In that form, the user has a choice to either enter in the parameters and then press the "OK" button or press the "Cancel" button and close both the report and the form. Right now everything work except for the fact the when the user selects the "cancel" button, they still get prompted to enter in the parameter values... Is there a way to supress the parameter input boxes that appear??? Here's my code...I added a little to prove to myself that the report isn't closing like it should....when I test to see if a report is open, it is -even after my Docmd.close ac report ran.

Private Sub Report_Open(Cancel As Integer)
Dim fcount As Integer 'used to count open forms
Dim rcound As Integer 'used to count open reports
On Error Resume Next

DoCmd.OpenForm "frmParameters", acNormal, , , acFormEdit, acDialog 'this suspends running of report until form is hidden or closed
'code pause here until a buttom is pushed...

fcount = IIf(Forms.Count = 0, 0, 1) 'counts how many forms are open and flags variable if at least one is open

If fcount = 0 Then 'runs if no forms are open, suppose to close the report if the parameter form is closed
DoCmd.Close acReport, "Report_2002GiftsAllDrops_CircPlan_SubReport(Buyers)" 'closes report again
End If
'problem is it still asks for parameters

rcount = IIf(Reports.Count = 0, 0, 1) 'returns 1, proves that the preceding statement doesn't close the report...??

End Sub

Any help would be greatly appreciated, thanks.

Andre
 
Hi Andre,

I haven't looked closely at your code, but the Report_Open event has a Cancel parameter. If you set Cancel = True it should cancel the opening of the Report and you shouldn't be prompted. If that doesn't help come back and I'll look more closely.

Enjoy,
Tony
 
Wow, that worked!! Thanks.

Could you explain what that does? Also, didn't the procedure dimension it as a integer, so how can I set it to 'true'?? (which is binary, isn't it?) I'm still very new to vba. Thanks again!!
 
Hi Andre,

It's passed to the routine specifically for this purpose. All events which can be canceled have a Cancel parameter.

Underneath everything FALSE has a value of zero and TRUE a value of -1, so Integer works just as well as Boolean. Off the top of my head I think any value other than -1 is taken as false, but don't take that as gospel.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top