Deleting spaces at the right

M

Maracay

Hi Guys,

I have this code to generate a file:

FileHandle = FreeFile()
Open strFileName For Output As FileHandle
On Error GoTo Err_handler
Dim rs As Recordset
Set rs = Recordset

rs.MoveFirst

Do Until rs.EOF
Print #FileHandle, Nz(Fname), Nz(LName)
Print #FileHandle, Nz(address)
Print #FileHandle, Space(10)
rs.MoveNext
Loop

Close #FileHandle

The problem is that Fname is 60 character long and in the file shows:
John Smith
And what I want is:
John Smith

I want to eliminate the empty spaces at the right, I try LTRIM and RTRIM but
didn’t work.
 
S

Stefan Hoffmann

hi,
I have this code to generate a file:
FileHandle = FreeFile()
Open strFileName For Output As FileHandle
On Error GoTo Err_handler
Dim rs As Recordset
Set rs = Recordset
Reorder this to:

On Local Error Goto Err_Handler

Dim rs As DAO.Recordset

Dim FileHandle As Long

Set rs = CurrentDb.OpenRecordset("..")

If Not rs.Bof And Not rs.Eof Then
FileHandle = FreeFile
Open strFileName For Output As FileHandle
'...
Close #FileHandle
End If


Print #FileHandle, Nz(Fname), Nz(LName)
The problem is that Fname is 60 character long and in the file shows:
John Smith
And what I want is:
John Smith
Use Trim():

Print #FileHandle, Trim(Nz(Fname, "") & Nz(LName, ""))



mfG
--> stefan <--
 
H

Harvey Thompson

Maracay said:
Hi Guys,

I have this code to generate a file:

FileHandle = FreeFile()
Open strFileName For Output As FileHandle
On Error GoTo Err_handler
Dim rs As Recordset
Set rs = Recordset

rs.MoveFirst

Do Until rs.EOF
Print #FileHandle, Nz(Fname), Nz(LName)
Print #FileHandle, Nz(address)
Print #FileHandle, Space(10)
rs.MoveNext
Loop

Close #FileHandle

The problem is that Fname is 60 character long and in the file shows:
John Smith
And what I want is:
John Smith

I want to eliminate the empty spaces at the right, I try LTRIM and
RTRIM but didn't work.

Maracay

The Access 2003 help, under "Print # Statement" contains the sentence:
"A space has the same effect as a semicolon."

WRONG!

if the arguments are separated by a comma, each argument is placesd in a
separate 'print zone.' To get the result you want use:
Print #FileHandle, Nz(Fname); " "; Nz(LName)
Note: one comma, two semicolons
 

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

Similar Threads


Top