Frustrated! Report closing immediately!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code on the Detail section of my report....only because
I've tried the OnOpen, Activate etc... However, when I click OK on my
parameter form (DetailedCredits) it flashes up the report preview for the
briefest of seconds and then everything closes.

When I take this code away, it works fine and stays open as normal. But...I
need this report to hide one or two of my columns depending on what is
selected on the form. I based the coding on the coding I found in Northwind.
Is there anything wrong? Can you suggest something? Thanks.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Forms!DetailedCredits!HFees = "No" Then
Me!HandlingFeeAmount_Label.Visible = False
Me!HandlingFeeAmount.Visible = False
Else
Me!HandlingFeeAmount_Label.Visible = True
Me!HandlingFeeAmount.Visible = True
End If

If Forms!DetailedCredits!Discounts = "No" Then
Me!DiscountAmount_Label.Visible = False
Me!DiscountAmount.Visible = False
Else
Me!DiscountAmount_Label.Visible = True
Me!DiscountAmount.Visible = True
End If

End Sub
 
you have

If Forms!DetailedCredits!HFees = "No" Then

if this is a Yes/No field, do not use "no", use False


If Forms!DetailedCredits!HFees = False Then

OR

If NOT Forms!DetailedCredits!HFees Then


you can also do this:

-------------------

dim mBoo as boolean
mBoo = Forms!DetailedCredits!HFees

Me.HandlingFeeAmount_Label.Visible = mBoo
Me.HandlingFeeAmount.Visible = mBoo

-------------------

.... same with Forms!DetailedCredits!Discounts


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
Thanks for the reply Crystal.

I tried the first option (False instead of No) but got no response at all.

With the Boolean option I used the following code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim mBoo As Boolean
Dim nBoo As Boolean
mBoo = Forms!DetailedCredits!HFees
nBoo = Forms!DetailedCredits!Discounts

Me.HandlingFeeAmount_Label.Visible = mBoo
Me.HandlingFeeAmount.Visible = mBoo

Me.DiscountAmount_Label.Visible = nBoo
Me.DiscountAmount.Visible = nBoo
End Sub

but exactly the same thing happened! The report opens but closes immediately
(split second).....aargh! This is so frustrating!
 
Hi Cindy,

what other code do you have behind the report?

dim mBoo as boolean

mBoo = Forms!DetailedCredits!HFees
Me.HandlingFeeAmount_Label.Visible = mBoo
Me.HandlingFeeAmount.Visible = mBoo

mBoo = Forms!DetailedCredits!Discounts
Me.DiscountAmount_Label.Visible = nBoo
Me.DiscountAmount.Visible = nBoo

put

Option Explicit

at the top of the module, then when you compile your code

Debug, Compile

....you spelled mBoo wrong in one of your lines -- this will
catch it

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
I thought I would have to distinguish between what's happening with HFees and
Discounts so I made one mBoo and one nBoo.....not so logical?
 
Debug>Compile is highlighting .Visible and saying that the method or data
member doesn't exist?
 
you can use the same variable -- first for one and then for
the other



Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
for which control? maybe the NAME is not right -- check the
property sheet

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
The Control Name is correct because it came up on an auto list and I selected
it (and I know them all!). This is the only code I have behind this report.
Would Visible be not recognised because of the libraries I have referenced, I
have VB, Access, etc etc

I'm confused about using the same declaration for each thing...

If i use mBoo for HFees being True or False, how can I use the same for
Discounts. Because HFees might be True and Discounts False at the same time,
ie, someone might wish to see the report but only without Discounts.

I know this is pushing it, but any other ideas? Thanks heaps
 
Sorry, should have mentioned the error is being highlighted for
HandlingFeeAmount not HandlingFeeAmount_Label. That's as far as it gets.
 
I did it! I did it!

Option Explicit

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim mBoo As Boolean
Dim nBoo As Boolean
mBoo = Forms!DetailedCredits!HFees
nBoo = Forms!DetailedCredits!Discounts

Me.HandlingFeeAmount_Label.Visible = mBoo
Me.HandlingFeeAmount.Visible = mBoo
Me.HFTotal.Visible = mBoo

Me.DiscountAmount_Label.Visible = nBoo
Me.DiscountAmount.Visible = nBoo
End Sub

Strangely, HandlingFeeAmount was called Text46, don't know why that happend!
For some reason I had to declare them separately (one mBoo and one nBoo). I
tried using both as mBoo and it either took away both or none.....so I tried
the declaring separately and it works! It works! Thank you so much for all
your help Crystal!
 
Hi cindy,

Congratulations! That is great, I am glad you got it.

you're welcome ;) happy to help

"Strangely, HandlingFeeAmount was called Text46, don't know
why that happend! "

could be that you already had it on there, then when you put
it on again, Access assigned it a different name -- then you
deleted the other control...

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
Back
Top