-
Oct 16th, 2021, 11:47 AM
#1
Thread Starter
Fanatic Member
Loop through text fields in Active reports
Hello everyone
I'm sorry to poste here as "Reporting Forum" seemed abondoned.
I need to loop through some text fields in the Activereport but I can't find a way.
Code:
Dim t As Integer
For t = 1 To 12
With ActiveReport1.Sections("Detail").Controls.Item("Field" & t)
' With ActiveReport1.Sections("Detail").Controls("Field" & t)
.Top = Form1.Text1(t).Top
.Left = Form1.Text1(t).Left
.Width = Form1.Text1(t).Width
.Height = Form1.Text1(t).Height
End With
Next
thank you all
-
Oct 16th, 2021, 12:33 PM
#2
Re: Loop through text fields in Active reports
Try something like this
Code:
Dim oCtl As Object
Dim oFld As Field
For Each oCtl In ActiveReport1.Sections("Detail").Controls
If TypeOf oCtl Is Field Then
Set oFld = oCtl
'--- do something with oFld
End If
Next
(air code)
cheers,
</wqw>
-
Oct 16th, 2021, 01:14 PM
#3
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
wqweto
thank you very much
unfortunately your code didn't work.
Besides, I don't want to loop through all the textfields but 12 only.
thank you
-
Oct 16th, 2021, 01:41 PM
#4
Re: Loop through text fields in Active reports
Honestly I have never tried looping through the fields on a report. You can easily set the properties by referring to the fields directly.
MyReport.Field1. whatever
That said I would imagine you may get different results than you expect by setting a field location = to the location of a text box on a form as that location will refer to the location within the detail section rather than the page.
What is it you are trying to accomplish?
-
Oct 16th, 2021, 02:02 PM
#5
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
MyReport.Field1. whatever
this is the only method that isworking up to now.
but it's a long process for 12 fields.
What is it you are trying to accomplish?
I'm trying to set the position, size, fonts... of the report fields the same as the ones on the form
thanks
Last edited by newbie2; Oct 16th, 2021 at 04:21 PM.
-
Oct 16th, 2021, 02:25 PM
#6
Re: Loop through text fields in Active reports
Originally Posted by newbie2
unfortunately your code didn't work.
It works here ¯\_(ツ)_/¯
Originally Posted by newbie2
Besides, I don't want to loop through all the textfields but 12 only.
You can set the control's Tag propertry at design time. Then filter by checking its content with InStr inside the For Each loop.
Edit: More sample code. This 110% works here (tested)
Code:
'--- code in ActiveReport1
Option Explicit
Friend Sub frInit()
Dim oCtl As Object
Dim oFld As Field
For Each oCtl In Detail.Controls
If TypeOf oCtl Is Field Then
Set oFld = oCtl
If InStr(1, oFld.Tag, "blue", vbTextCompare) > 0 Then
Debug.Print oFld.Name
End If
End If
Next
End Sub
Code:
'--- code in Form1
Option Explicit
Private Sub Form_Load()
With New ActiveReport1
.frInit
End With
End Sub
cheers,
</wqw>
Last edited by wqweto; Oct 16th, 2021 at 02:29 PM.
-
Oct 16th, 2021, 04:21 PM
#7
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
wqweto
thank you again
your code is working
but my problem is :
I'm trying to set the position, size, fonts... of the report fields the same as the ones on the form
Code:
With Field1
.Top = Form1.Text1(1).Top
.Left = Form1.Text1(1).Left
.Width = Form1.Text1(1).Width
.Height = Form1.Text1(1).Height
.Font.Size = Form1.Text1(1).Font.Size
.Font.Name = Form1.Text1(1).Font.Name
.Alignment = Form1.Text1(1).Alignment
.ForeColor = Form1.Text1(1).ForeColor
.Font.Bold = Form1.Text1(1).Font.Bold
.Font.Underline = Form1.Text1(1).Font.Underline
End With
I want to do that for 12 textfields.
-
Oct 16th, 2021, 05:34 PM
#8
Re: Loop through text fields in Active reports
Why position the fields, set the fonts and so on in the designer? That is the way you would normally do it.
-
Oct 16th, 2021, 05:44 PM
#9
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
Originally Posted by DataMiser
Why position the fields, set the fonts and so on in the designer? That is the way you would normally do it.
the fonts and position of the form textoxes are set at runtime.
-
Oct 18th, 2021, 04:42 PM
#10
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
-
Oct 18th, 2021, 07:06 PM
#11
Re: Loop through text fields in Active reports
Originally Posted by newbie2
the fonts and position of the form textoxes are set at runtime.
So are you saying they are set by the user at runtime?
-
Oct 18th, 2021, 07:11 PM
#12
Re: Loop through text fields in Active reports
btw if you just set each field directly it would be done already, Sure it would be several lines of code but that is not a big deal and is easy enough to do. Take a look at the raw .frm file in a text editor sometime. You will see there is a separate line in there for every setting on every control.
-
Oct 19th, 2021, 04:30 AM
#13
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
Originally Posted by DataMiser
So are you saying they are set by the user at runtime?
yes that's it
-
Oct 19th, 2021, 08:05 AM
#14
Lively Member
Re: Loop through text fields in Active reports
Originally Posted by newbie2
Hello everyone
I'm sorry to poste here as "Reporting Forum" seemed abondoned.
I need to loop through some text fields in the Activereport but I can't find a way.
Code:
Dim t As Integer
For t = 1 To 12
With ActiveReport1.Sections("Detail").Controls.Item("Field" & t)
' With ActiveReport1.Sections("Detail").Controls("Field" & t)
.Top = Form1.Text1(t).Top
.Left = Form1.Text1(t).Left
.Width = Form1.Text1(t).Width
.Height = Form1.Text1(t).Height
End With
Next
thank you all
1) Is the report external to the VBP project or is it incorporated into the project?
2) In which event of the report did you enter the code?
3) Can you post the report with code?
-
Oct 19th, 2021, 04:27 PM
#15
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
Is the report external to the VBP project or is it incorporated into the project?
incorporated into the project
In which event of the report did you enter the code?
in ActiveReport_Initialize event
Can you post the report with code?
no other code in the report other than the one you have quoted.
thank you
-
Oct 20th, 2021, 03:44 AM
#16
Lively Member
Re: Loop through text fields in Active reports
Have you tried to use the Detail_Format() event?
-
Oct 20th, 2021, 05:06 PM
#17
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
Originally Posted by LeoFar
Have you tried to use the Detail_Format() event?
sorry no success
-
Oct 20th, 2021, 05:15 PM
#18
Re: Loop through text fields in Active reports
Just curious here but if you want the report to look like the form why not just use the printform method?
Also if you want to use a report what is the reason that you don't just set the controls directly? Sure a loop would be less code but if you are having trouble getting a loop to work then the logical thing to do would be forget the loop and do a direct assignment. At runtime it is going to be about the same speed, possibly a little faster.
-
Oct 20th, 2021, 05:57 PM
#19
Thread Starter
Fanatic Member
Re: Loop through text fields in Active reports
Just curious here but if you want the report to look like the form why not just use the printform method?
I want to care about the quality of printing. The quality of printing differs a lot between the two methods.
Also if you want to use a report what is the reason that you don't just set the controls directly?
The controls on the form can be resized and formatted by the user at runtime
if you are having trouble getting a loop to work then the logical thing to do would be forget the loop
It seems this is my remaining choice.
thank you
-
Oct 20th, 2021, 06:57 PM
#20
Re: Loop through text fields in Active reports
Originally Posted by newbie2
The controls on the form can be resized and formatted by the user at runtime
There is no reason you can't directly set the field properties at runtime. No loop required.
-
Oct 21st, 2021, 02:21 AM
#21
Lively Member
Re: Loop through text fields in Active reports
Originally Posted by newbie2
sorry no success
If you post a sample project that reproduces the problem we can take a look.
I could do it for you, but I would never know how you set up your project, form and report, with the risk of not guessing your need.
Last edited by LeoFar; Oct 21st, 2021 at 02:29 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|