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

Function which returns column name 1

Status
Not open for further replies.

Gary53045

Programmer
Feb 7, 2005
2
US
In crystal 9, is there any way to create a function which receives the column name as the argument and returns the column name instead of the column value?

e.g. MyFunction({Employees.Employee_Lastname}) returns 'Employee_Lastname' instead of 'smith'

I'm trying to create a custom function which accepts any field name and returns a tagged XML string using the field name as the tag

e.g. <Employee_Lastname>Smith</Employee_Lastname>
 
Why would you want to pass a column name to a function that then returns only the column name?

The function would be doing nothing.

Not sure of the intent of the tagged XML string either.

Where would this string be used, in Crystal?

You could probably use a stored procedure to do this, but that depends on the database.

You could create a formula in Crystal to do this as well by passing it a parameter:

"<"&{?myparameter}&{table.field}&"</"&{?myparameter}&">"

-k
 
Create a custom function as follows :

Function MyFunction (sFieldName as string)
MyFunction = replace(mid(sFieldName,instr(sFieldName,".")+1),"}","")
End Function

Then create a fowmula to call the function with the field name :

MyFunction ("{Employees.Employee_Lastname}")

Remember to enclose the field name in quotes.

HTH

Dan

 
Thanks for the replies.

I'm trying to create an easy way to produce an XML output file by embedding the tags as part of the report. I've looked at the Export to XML capabilities, and the standard schema is overly detailed for our need, and defining a custom schema doesn't give us the control over the attributes we'd like.

I was hoping to create a custom function that would allow me to generate the tags and data with a single call to the function for each data element. As it stands now, I have to create a separate function for each data element. My XML file may have dozens of data elements for each row, so I was trying to avoid creating dozens of functions.

Does anyone have any experience with the XML UFL from Mindconnection?
 
Dear DanAusten,

Well that is pretty darn spiffy !*

I used Basic syntax and had to change it to the following to stop crystal from complaining ... :

Function t(sFieldName as string)
t = replace(mid(sFieldName,instr(sFieldName,".")+1),"}","")
End Function

Otherwise, works as adverstised.

best regards,

ro

Rosemary Lieberman
rosemary-at-microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.

You will get answers more quickly if you read this before posting: faq149-3762
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top