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
Microsoft AccessWindows OSVBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Laurence Martin
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 ?"
Avatar of Laurence Martin

ASKER

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

Avatar of Laurence Martin

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Laurence Martin

ASKER

Thanks for the help.  It would be interesting to know why the different environments behave differently,
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo