Solved

Excel formatting from MSAccess

Posted on 2006-06-28
5
330 Views
Last Modified: 2008-01-09
I have a MSAccess utility that creates a XLS file and provides a bit of XLS formatting before I dump a recordset into it.

I and seeing an intermittent error in my code:

'Data Body Formatting
    With wksNew.Range("A6:R" & RecordCount)
        .Font.Size = 8
        .VerticalAlignment = xlVAlignCenter
        .BorderAround Weight:=xlThin
        .Borders(xlInsideVertical).Color = 15
        With .Borders(xlInsideHorizontal)
            .Weight = xlThin                          <----------Debug points to this line
            .Color = RGB(192, 192, 192)
        End With
    End With

Error:  Runtime Error '1004'  Unable to set the Weight Property of the Border Class.

I will get this error for a repeatable set of conditions related to the RecordSet, but NO error for a different set of conditions.  The actual data dump happens well after this command:


'Dump RecordSet to XLS

    Dim rs As DAO.Recordset
    Dim prm As DAO.Parameter
   
    Set qdf = CurrentDb.QueryDefs("DMSReport")
    'Evaluate the parameters from the form references
    For Each prm In qdf.Parameters
        prm.Value = Eval(prm.Name)
    Next
    Set rs = qdf.OpenRecordset(dbOpenSnapshot)
       
    With wksNew
        .Range("A7").CopyFromRecordset rs
    End With


Help??
0
Comment
Question by:markp99
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
Is it not better to apply formatting after u done CopyFromRecordset? just a thought

see this
http://support.microsoft.com/default.aspx?scid=kb;en-us;277577
0
 
LVL 34

Expert Comment

by:jefftwilley
Comment Utility
**** Don't accept as Answer. Just curious*****
Hi Mark p
I'm wondering, if you create your code as a macro inside your spreadsheet and run it from there...is the border weight available within your workbook?

also, you might want to just line it out

.Borders(xlInsideHorizontal).Weight = xlThin                          <----------Debug points to this line
.Borders(xlInsideHorizontal).Color = RGB(192, 192, 192)
 
0
 

Author Comment

by:markp99
Comment Utility
I found my problem, but seems strange:

There was an issue with my "RecordCount" variable (RecordCount = actualnorecords + 6).  I use this to format only the extent of the XLS sheet that will actually contain data.   In the error condition: RecordCount = 6, which is the Header of my XLS sheet which I formatted just before the problem section.

All is well now that I am getting a reliable RecordCount (there was a NULL vs "" issue in my DCount statement).
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now