Dynamic Report (2)

jtoutou

Registered User.
Local time
Today, 23:03
Joined
Dec 1, 2007
Messages
19
there is a query called "My Query" which is dynamic
this query is based on a table ..
in this table i change the caption on fields.
when i run the query i have "field names" the caption i was set.
i made then a code to open the report...which is also dynamic ..
this is the code i found

Dim stDocName As String
Dim accobj As AccessObject
On Error GoTo Err_Command100_Click
stDocName = "MY QUERY"

Set accobj = Application.CurrentProject.AllReports.Item(stDocName)
If accobj.IsLoaded Then
If accobj.CurrentView = acCurViewPreview Then
DoCmd.Close acReport, stDocName
DoCmd.OpenReport stDocName, acPreview
End If
Else
DoCmd.OpenReport stDocName, acPreview
End If

the problem is that in the report i did not have the caption i was set but the initial field name...how can i change it...
thank you
 
Last edited:
there is a query called "My Query" which is dynamic
this query is based on a table ..
in this table i change the caption on fields.

the problem is that in the report i did not have the caption i was set but the initial field name...how can i change it...
You'll probably have to set the caption string equal to the actual field name. I think the caption strings are just "fronts" to represent a field. I doubt there is a caption property that you can reference either, because it's technically not part of the table object. If you're talking about labels on a report, I don't think captions automatically transfer to them from a table, but if you make an autoform from a table, I think they do transfer to the labels.
 
i agree with you totally...i spend at least 13 hours to find out what is going on....the caption property on tables is the label on the field when used on a form...but how can i set the caption string equal to the actual field name when the query and also the report is dynamic.
the query is created depending on users choises (which fields user choose with a check box) ....maybe the code needs also an SQL statemen.i am very confused...thanx for your reply...i need further help if you can ....
 
the caption property on tables is the label on the field when used on a form...but how can i set the caption string equal to the actual field name when the query and also the report is dynamic.
I doubt you can. When a control is bound to a field, it has no caption. They are meant for labels.

If you still want to go through with this, then how about the following:

With the OnOpen event of the report, loop through all the label type controls (which should, by default, have display names equal to the field names that they are representing), and then assign the appropriate caption to each one of them. If there is a pattern to the captions, the loop will be easier too.

I just have one other question for you: Why go through all this trouble? It's obvious that you can do this, but don't you have other things to worry about besides making your report look perfect? ;) ;)
 
YOUR ARE VERY RIGHT ...Thanx a lot for your advise..i'll check it for a while in the way you told me...
 

Users who are viewing this thread

Back
Top Bottom