troubleshooting Question

Runtime Error on Workbooks.Add

Avatar of Laurence Martin
Laurence MartinFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft AccessWindows OSVBAMicrosoft ExcelMicrosoft Office
8 Comments1 Solution73 ViewsLast Modified:
I have an Access Database that wants to send information in an Excel spreadsheet.

An extract of the code is as follows, but the code falls over at .Workbooks.Add with the following error.

Run-time error '-2147417851 (80010105)'

We only get this error in a terminal server environment.  When on a Windows desktop it works fine.

Can anyone tell me what could be going wrong? or advise me how to make the code more robust.


'Call OpenEDRTemplate(strFilename, True, strOrderNo)
Set myXL = New Excel.Application

With myXL
    myXL.Visible = True
    .Workbooks.Add "\\sc-addfs-01\dfs\Orders\Templates\Error Damage Master Template.xltx"

    .ActiveWorkbook.SaveAs (strFilename)
    Set myWkb = .ActiveWorkbook
    Set myWks = myWkb.ActiveSheet
    With myWks
        .Range("dealer_name").Value = strDealer
        .Range("sc_acno").Value = strACNo
        .Range("sc_order_no").Value = strOrderNo
        .Range("customer_name").Value = strCustomer
        .Range("dealer_order_no").Value = strDealerOrderNo
        'write room names
        bytItem = 1
    End With
    stSelect = "SELECT dbo_tbl131OrderLine.f131intLineNumber, dbo_tbl131OrderLine.f131strRoom, dbo_tbl103Orders.f103strSCOrder "
    stFrom = "FROM (dbo_tbl103Orders INNER JOIN dbo_tbl130OrderLineBase ON dbo_tbl103Orders.f103intOrderId = dbo_tbl130OrderLineBase.f130intOrderId) INNER JOIN dbo_tbl131OrderLine ON dbo_tbl130OrderLineBase.f130intOrderLineBaseId = dbo_tbl131OrderLine.f131intOrderLineBaseId "
    stWhere = "WHERE (((dbo_tbl131OrderLine.f131intLineNumber) = " & bytItem & ") And ((dbo_tbl103Orders.f103strSCOrder) = '" & strOrderNo & "')) ORDER BY dbo_tbl131OrderLine.f131intLineNumber;"

    stSQL = stSelect & stFrom & stWhere
    Set recEDROrder = CurrentDb.OpenRecordset(stSQL, dbOpenSnapshot, dbSeeChanges)
    If recEDROrder.RecordCount = 0 Then
        myXL.ActiveCell.Offset(bytItem).Value = recEDROrder!f131strRoom
        bytItem = bytItem + 1
        GoTo jump1
    End If
        Set recEDROrder = Nothing
    .ActiveWorkbook.Close (True)
End With
    Set myWks = Nothing
    Set myWkb = Nothing
    Set myXL = Nothing
Laurence Martin
Training Director

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros