Compile problem

T

Tom

I was reading that compiling my code would make the application run faster.
So within the VB tool I selected Debug/Compile.

I run a bunch of code which manipulates forms, and I am getting errors
whenever I call out a form property. For example (GroupHeader1).

How do I fix this?

++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit

Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
If [BomPnDash] = [PNNumb2] Then
GroupHeader1.Visible = False
Else
GroupHeader1.Visible = True
End If

End Sub
 
M

Marshall Barton

Tom said:
I was reading that compiling my code would make the application run faster.
So within the VB tool I selected Debug/Compile.

I run a bunch of code which manipulates forms, and I am getting errors
whenever I call out a form property. For example (GroupHeader1).

How do I fix this?

++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit

Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
If [BomPnDash] = [PNNumb2] Then
GroupHeader1.Visible = False
Else
GroupHeader1.Visible = True
End If

End Sub

Well, that code is in and manipulating a report, not a form.

What errors are you getting? Are you getting the errors
when you run the report or when you compile your project?

The only thing I can tell with the information you posted is
that maybe the report text box controls and/or record source
fields BomPnDash and PNNumb2 are not what you think they
are.

Note: Compiling your project is a good idea because it
catches syntax errors, undeclared variables and improper
object/property references. The code must be compiled
before the code can be executed so explicity compiling it
spends the time during you design changes instead of when
you want to run it. The time is the same so it's more a
matter of when the time is spent.
 
T

Tom

Marshall Barton said:
Tom said:
I was reading that compiling my code would make the application run
faster.
So within the VB tool I selected Debug/Compile.

I run a bunch of code which manipulates forms, and I am getting errors
whenever I call out a form property. For example (GroupHeader1).

How do I fix this?

++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit

Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
If [BomPnDash] = [PNNumb2] Then
GroupHeader1.Visible = False
Else
GroupHeader1.Visible = True
End If

End Sub

Well, that code is in and manipulating a report, not a form.

What errors are you getting? Are you getting the errors
when you run the report or when you compile your project?

The only thing I can tell with the information you posted is
that maybe the report text box controls and/or record source
fields BomPnDash and PNNumb2 are not what you think they
are.

Note: Compiling your project is a good idea because it
catches syntax errors, undeclared variables and improper
object/property references. The code must be compiled
before the code can be executed so explicity compiling it
spends the time during you design changes instead of when
you want to run it. The time is the same so it's more a
matter of when the time is spent.

Yes, my bad it is in a report. :~(
The code runs fine "uncompiled" I have been using it for years.

However when I try to "compile it", it gives the error
"Variable not defined"

Many thanks
Tom
 
M

Marshall Barton

Tom said:
Tom wrote: []
Option Compare Database
Option Explicit

Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
If [BomPnDash] = [PNNumb2] Then
GroupHeader1.Visible = False
Else
GroupHeader1.Visible = True
End If

End Sub
[]
The only thing I can tell with the information you posted is
that maybe the report text box controls and/or record source
fields BomPnDash and PNNumb2 are not what you think they
are.
[]

The code runs fine "uncompiled" I have been using it for years.

However when I try to "compile it", it gives the error
"Variable not defined"


Inspect the line that the compiler highlights for the
variable that is not declared and then declare it in the
approporiate place. If it's a mispelled name, then either
the line should be removed or corrected to get the code to
perform as designed without the error.
 
T

Tom

Marshall Barton said:
Tom said:
Tom wrote: []
Option Compare Database
Option Explicit

Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As
Integer)
If [BomPnDash] = [PNNumb2] Then
GroupHeader1.Visible = False
Else
GroupHeader1.Visible = True
End If

End Sub
[]
The only thing I can tell with the information you posted is
that maybe the report text box controls and/or record source
fields BomPnDash and PNNumb2 are not what you think they
are.
[]

The code runs fine "uncompiled" I have been using it for years.

However when I try to "compile it", it gives the error
"Variable not defined"


Inspect the line that the compiler highlights for the
variable that is not declared and then declare it in the
approporiate place. If it's a mispelled name, then either
the line should be removed or corrected to get the code to
perform as designed without the error.

Sorry for bing a newbe, but I guess I just don't get it...
"GroupHeader1.Visible" is not a variable. It is a Report attribute right,
Just like a text/lable attribute, so why would you need to declare it and/or
how would you declare it?

- is it a String, Object, Variant, etc
- also how would I assign GroupHeader1.visible to it.
- how would you then issue the command?

thank for helping
Tom
 
M

Marshall Barton

Tom said:
Sorry for bing a newbe, but I guess I just don't get it...
"GroupHeader1.Visible" is not a variable. It is a Report attribute right,
Just like a text/lable attribute, so why would you need to declare it and/or
how would you declare it?


If that's the line the compiler is complaining about, then
you would bit declare GroupHeader1. However, the compiler
is saying the name, GroupHeader1, is undefined, so double
check that it really is the name the report section and that
it is spelled correctly.

If that is the right name, then maybe something is confused
and try qualifying the name with its object. You can use Me
for the report object when the code is in the same
form/report that you are manipulating:
Me.GroupHeader1.Visible = ...

Alternatively, skip the name and reference the section by
its numeric index;
Me.Section(5).Visible = ...

Other than that, I am out of ideas.
 
T

Tony Toews [MVP]

Tom said:
I was reading that compiling my code would make the application run faster.

Not really. With todays CPUs the difference isn't noticeable.
However, as Marsh points out, you should be compiling on a very
regular basis.

Tony
 

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