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

HELP: ActiveReports!!!!!!!!!!!! ( VB 6.0)

Status
Not open for further replies.

Ausburgh

Programmer
Jul 21, 2004
62
0
0
US
HELP, this desperate VB beginner!!!!

I created a Database Application: VB front-end and MS Access back-end. Now I'm trying to generate a couple of reports.

I'm using a DAO control but I am STUCK big time: I'm trying to get a percentage (field2/field1 - values passed from the Access table) and put the result in field3 but it's not working.

By the way this is the extent of my code so far.

-------------------------------
Option Explicit

Private Sub Detail_Format()

If Field1.DataValue = 0 And Field2.DataValue = 0 Then
Field3.DataValue = 0
Else
Field3.DataValue = Field2.DataValue / Field1.DataValue
End If
End Sub

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

Thanks in advance
 
<but it's not working.

I could spend two days and seventeen pages of densely printed material elaborating on what this COULD mean, and all the ways it could then be fixed. As one example: you might not be calling the Detail_Format Sub at all. So, rather than provide other examples of what the problem probably isn't, perhaps you can elaborate on what "not working" means? :)

Thanks,

Bob
 
I keep getting the following error:

Runtime error '11'
Division by zero


Thanks,

Wale
 
Aha. Well, that helps. You're dividing by zero. That will happen in your code if Field1 is a zero and Field2 isn't. See if you can explain why, and what you need to do to fix it.....(sorry, you got an instructor here, you're gonna have to live with it).

HTH

Bob
 

That's the problem.

Why isn't the code below handling that?

-------------------------------------------
If Field1.DataValue = 0 And Field2.DataValue = 0 Then
Field3.DataValue = 0
Else
Field3.DataValue = Field2.DataValue / Field1.DataValue
End If

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

Thanks
 
Consider the difference between AND and OR ...

(although in fact I'd be tempted to drop the second part of the clause altogether)
 
Aha.

I guess I should have used "Or" instead of "And".
---------
If Field1.DataValue = 0 Or Field2.DataValue = 0 Then
Field3.DataValue = 0
Else
Field3.DataValue = Field2.DataValue / Field1.DataValue
End If
-------

Thanks Bob.

 
Thanks Strongm.

I was typing my response as you were responding too.
 
The light dawns. :)

And also, I would suggest that you consider what strongm says about dropping the second part of the clause altogether. See what happens when you fully work out all the possibilities that could occur if you did so, and ask yourself what added functionality (if any) you get by evaluating Field2 in the If clause. You'll find it interesting and instructive if you do.

HTH

Bob
 

Here's a new inquiry.


Is there a way to setup the report to print in a "Landscape" Layout -- because Portrait isn't wide enough for my printout?

Thanks
 


You are both absolutely correct -- I dropped the "Or Field2.DataValue = 0" -- it wasn't needed.

Class is in session ... Masters teach me kung fu!:)

Thanks.
 
I'm trying to set the page to landscape - I found the code below but when I ran it I got the following error:

----
Compile error:
Invalid qualifier
----

Please help! Thanks in advance


------
' ActiveReports defaults to the current printer settings
' to set the orientation property in the ReportStart event

Private Sub ActiveReport_ReportStart()
Me.PageSettings.Orientation = ddOLandscape
End Sub
 
I'm trying to set the page to landscape - I found the code below but when I ran it I got the following error:

----
Compile error:
Method of Data member not found
----

Please help! Thanks in advance


------
' ActiveReports defaults to the current printer settings
' to set the orientation property in the ReportStart event

Private Sub ActiveReport_ReportStart()
Me.PageSettings.Orientation = ddOLandscape
End Sub


 
I don't know anything about ActiveReports, but have you checked in the object browser to make sure you're referencing the property correctly and that your constant is correct? I know if I'm using a data report, it's referenced like this:

rptName.Orientation = rptOrientLandscape


Just a thought... like I said I don't know nothin' 'bout ActiveReports.

Kevin
 

Using DAO to link an Access database to an ActiveReport as I indicated in the original post.

I am getting an error:

Runtime Error ‘6’ Overflow

From: Field126.DataValue = Field124.DataValue / Field123.DataValue

Where Field124 = $7757.43, Field123 = $112,950.51

Field126 should be 6.87%

I don’t understand how it can yield an overflow.
 
For future reference, it's usually best to put new questions in a new thread. This one is kind of a gray area, since they're a bit related. But the general idea is to make answers as easy as possible to find for everyone. So, if information is buried under a heading that doesn't describe the information, that's hard to find, and if related information is in multiple threads, that's hard to find too.

As for Overflow problems: they usually occur when you perform some sort of arithmetic operation and assign the result to a variable type that can't hold it. An obvious example:
Code:
Dim x as integer
Dim y as integer
Dim z as integer
x = 14000
y = 22000
z = x + y
This will produce an overflow, because the result is 36000, and the code tries to assign that result to z, which, as an integer, will only hold 32768.

In your case, the overflow could be in a few different places. You'll need to try to break apart your process. For example, create variables, assign your variables to them, and perform your arithmetic. If that all works, then you know that the problem is somewhere in your field definitions. In that case, you might want to try posting in the Access forum, where people with more experience with Access might know right off what's going on.

HTH

Bob
 

This is by no means a slam to anyone, I just happened to think of it when reading this post.
One of the most valuable things my instructor taught me (some 20 years ago) was this: I would get stuck on a programming problem and would go to him for help. His reply was always this, "Read up on the documentation, and view the samples, and refer to the index. I promise you, you will not need my answer." I have implemented that in my career and I have learned far more by using it.
 
We could have all saved a lot of time and effort if Ausburgh had read (and taken notice) of faq222-2244 as previously advised!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top