Solved

Excel formatting from MSAccess

Posted on 2006-06-28
5
343 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
ID: 17000994
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
ID: 17001250
**** 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
ID: 17001521
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
ID: 17893944
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views 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 Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

895 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

15 Experts available now in Live!

Get 1:1 Help Now