Can this be done?

teiben

Registered User.
Local time
Today, 19:39
Joined
Jun 20, 2002
Messages
462
I've created a report, and I have a limited amount of space to work with. I have a field called salesperson, in which the salesperson enters both their first and last name. Is it possible, in the report to just extract the salespersons initials?
 
You need to look up the Left() function.
 
Function GetInitials(txtName As Variant)
Dim Temp As String
Dim count As Integer

Temp = txtName

count = Len(txtName)
GetInitials = left(txtName, 1)
Do While count <> 0
If left(Temp, 1) = Chr(32) Or left(Temp, 1) = Chr(45) Then
GetInitials = GetInitials & Mid(Temp, 2, 1)
End If

count = count - 1
Temp = right(Temp, count)
Loop
End Function
 
Wouldn't it be easier if you had a table that holds all the Sales People and they just selected themselves from a combobox?
 
Thanks Rich, but how do I attach it? Sorry I'm a novice
 
create a module and paste the code in this module.

on the report where the field name you want the initials go to properties and set the control source to =GetInitials([yourfield])
and run the report.
 
Hey thanks, but I couldn't get it to run. I get the message Enter a Parameter Value: for Get Initials
any other idea's?
 
In the module change the first line of the function to:

Code:
Public Function GetInitials(txtName As Variant)


Did you put a space between GetInitials as you say the parameter is asking for? Could just be that!
 
Where have you put the =GetInitials([yourfield]) statement?

I should go in the controlsource of the textbox where you want to show the initials.
Also make sure that the function is in a module, not in the code behind the report.
 
Thanks a million, Mile-O-Phile, that's what it was, I changed the line to Public Function GetInitials(txtName As Variant), and now it works!
:D
 
Another question, how would I use the same function in a different report? I've tried and it won't work.
 
Is the function in a separate module or in the code behind the original report. You must create a new module and paste the code there. This makes the function available to the whole of the Db, not just the report where it is likely currently situated.
 
Its a stand alone module, which I thought meant that I could access it anywhere in the db
 

Users who are viewing this thread

Back
Top Bottom