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

Report Output To *.rtf not keeping text format

Status
Not open for further replies.

trackwan

MIS
May 14, 2004
2
US
I have a report with conditional formating to change the text format if dates <= Now.
Example:
If me.txtAuto <= Now Then
me.txtAuto.ForeColor = 255
me.txtAuto.FontBold = True
me.txtAuto.FontItalic = True

Else
me.txtAuto.ForeColor = -2147483640
me.txtAuto.FontBold = False
me.txtAuto.FontItalic = False
End If

It works fine in Access, but when I use the Export or Output To commands, every other column is red regardless of the date that appears. Is there a way I can export it to .rtf or .xls and keep the formating? Any help would be greatly appreciated.
 
If you use "Export" or "Output to command," you have no control over Access's behavior. So I do not think there is anything you can do about it.

On the other hand, you can write codes with Word or Access object model to create a Word or Excel file with Access data. This way you can manipulation every possible formatting in Word or Excel.

Seaport
 
Thanks for the help seaport. [thumbsup2]

Could you elaborate on how to use object models to create a Excel or Word document.
 
That would be a post in the "Microsoft: Office" forum. Anyway, you need to get a book like "MS Office2000 Visual Basic Programmer's Guide." Here are some sample code for copying data into a new excel file.
Code:
    On Error GoTo eh
    
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlWks As Excel.Worksheet
    Dim rst As ADODB.Recordset

    Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Add(strTemplateFile)
    Set xlWks = xlBook.Worksheets("Sheet1")
    rst.Open strSql, CurrentProject.Connection, adOpenKeyset
    xlWks.Range("A2").CopyFromRecordset rst
ex:
    on Error Resume Next
    xlApp.Visible = True
    Set xlWks = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
    
    Exit Function
eh:
    msgbox err.description
    Resume ex

When you manipulate Office application with VBA code, be sure to have proper error-handling all the time. Otherwise you may get invisiable applications left in the memory and you have to goto task manager to kill them.

Hope this helps.

Seaport
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top