Link to home
Start Free TrialLog in
Avatar of Laurence Martin
Laurence MartinFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Runtime Error on Workbooks.Add

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.

User generated image

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.

Cheers


'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
        .Range("b19").Select
    End With
   
jump1:
    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
        recEDROrder.Close
    Else
        recEDROrder.MoveFirst
        myXL.ActiveCell.Offset(bytItem).Value = recEDROrder!f131strRoom
        bytItem = bytItem + 1
        recEDROrder.Close
        GoTo jump1
    End If
        Set recEDROrder = Nothing
   
    'protect
    myWkb.ActiveSheet.Protect
       
   
    .ActiveWorkbook.Close (True)
    .Quit
End With
    Set myWks = Nothing
    Set myWkb = Nothing
    Set myXL = Nothing
Avatar of Louis LIETAER
Louis LIETAER
Flag of France image

Hi,

Is excel installed on your server ?

regards
Avatar of Laurence Martin

ASKER

Yes, and the users can open the file manually.
You may have an issue with "\\sc-addfs-01\dfs\Orders\Templates\Error Damage Master Template.xltx", I mean "is the share server working in TS environment ?"
I don't administer the server, so I don't know.  Is there a way to test that?
Yes with an RDP client,  goto explorer just key the path "\\sc-addfs-01\dfs\Orders\Templates" and look if you see the excel file

Yes, that works.

Thank-you for your help Louis
ASKER CERTIFIED SOLUTION
Avatar of Laurence Martin
Laurence Martin
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help.  It would be interesting to know why the different environments behave differently,