I get vba error 462 the remote server machine does not exist or is unavailable

Hello Fellows

I get the above error when i run the code bellow , but when i re-run it after the error occur, the code seems to Work fine. For sure im missing something in it. Can you point me the right way to do this?



Thanks in advanced.

First sub:

Private Sub Command54_Click()


Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Verb = acOLEVerbOpen
Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Verb = acOLEVerbOpen
Set GeraKit0 = Forms!frmFScomposicao!subfrmKitCenas!FSKitCenasOLE.Range

With GeraKit0.Select
GeraKit0.WholeStory
GeraKit0.Delete
End With

Dim FirstTime As Integer
FirstTime = 1

Me.FirstTimeBox = FirstTime

Forms!frmFScomposicao!PRODUCAO.SetFocus

DoCmd.RunCommand acCmdRecordsGoToFirst
For f = 1 To Forms!frmFScomposicao!PRODUCAO![Tiroliro]
Me.FirstTimeBox = FirstTime

Call CompilarKitDiaGravacao
Forms!frmFScomposicao!PRODUCAO.SetFocus
FirstTime = FirstTime + 1

DoCmd.RunCommand acCmdRecordsGoToNext

Next f

DoCmd.RunCommand acCmdRecordsGoToFirst

End Sub

Open in new window



Second sub:

Public Sub CompilarKitDiaGravacao()
'Set cenaspararecolher = Forms!frmFScomposicao!PRODUCAO.Action = acOLEActivate
Set cenaspararecolher = Forms!frmFScomposicao!PRODUCAO![Prod_Cena_Guiao].Range
With cenaspararecolher.Select
cenaspararecolher.WholeStory
cenaspararecolher.Copy
Set cenaspararecolher = Nothing
End With

If Forms!frmFScomposicao.FirstTimeBox = 1 Then

Set Vinho = Forms!frmFScomposicao!subfrmKitCenas!FSKitCenasOLE.Range
With Vinho.Select
Selection.EndKey wdStory
Selection.InsertBreak Type:=wdSectionBreakContinuous
Selection.PasteAndFormat wdPasteDefault
End With
Forms!frmFScomposicao!FirstTimeBox = Forms!frmFScomposicao!FirstTimeBox + 1

Else

Set Vinho = Forms!frmFScomposicao!subfrmKitCenas!FSKitCenasOLE.Range
With Vinho.Select
Selection.EndKey wdStory
Selection.InsertBreak 'Type:=wdSectionBreakContinuous
Selection.PasteAndFormat wdPasteDefault
End With
 End If


End Sub

Open in new window

Armando Vilela Baiões Self-taughtAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Helen FeddemaCommented:
It seems that you are somehow working with a Word document (as indicated by some of the code, such as inserting a continuous section break), but I don't see code to either create a Word doc or set a reference to an existing doc.  What exactly is the code doing (in words)?
0
Armando Vilela Baiões Self-taughtAuthor Commented:
Hello.
I have a main form with two sub forms one of the sub forms contains a list of several OLE selected word documents, in which I loop, passing all these documents to another sub form, which also contains an OLE Field, which will gather these Documents, in one.
0
Armando Vilela Baiões Self-taughtAuthor Commented:
It may be something to do with one of the subforms, only when I make the selection of new documents the error occurs the first time I try the code, then if I try again, the code works.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Armando Vilela Baiões Self-taughtAuthor Commented:
I quit (for today), maybe i need some rest... If anyone have any ideia, please post!
0
Armando Vilela Baiões Self-taughtAuthor Commented:
I made some changes to the code, but im still getting the same error, but on a diferent line (underscored).

Heres the code so far:

Public Sub CompilarKitDiaGravacao()

Dim CenasParaRecolha As Object
Dim DocumentoDestino As Object

        Set CenasParaRecolha = Forms!frmFScomposicao!PRODUCAO![Prod_Cena_Guiao].Object.Application.WordBasic
        Forms!frmFScomposicao!PRODUCAO![Prod_Cena_Guiao].Action = acOLEActivate
        With CenasParaRecolha
        Selection.WholeStory
        Selection.Copy
        End With

If Forms!frmFScomposicao.FirstTimeBox = 1 Then
    
    Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Action = acOLEPaste

        Set DocumentoDestino = Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Object.Application.WordBasic
        Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Action = acOLEActivate
        With DocumentoDestino
        Selection.WholeStory
        Selection.Delete
        Selection.EndKey wdStory
        Selection.InsertBreak Type:=wdSectionBreakContinuous
        Selection.PasteAndFormat wdPasteDefault
        End With

    Forms!frmFScomposicao!FirstTimeBox = Forms!frmFScomposicao!FirstTimeBox + 1

Else

        Set DocumentoDestino = Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Object.Application.WordBasic
        Forms!frmFScomposicao!subfrmKitCenas![FSKitCenasOLE].Action = acOLEActivate
        With DocumentoDestino
        Selection.EndKey wdStory
        Selection.InsertBreak 'Type:=wdSectionBreakContinuous
        Selection.PasteAndFormat wdPasteDefault
        End With
 
End If

Set CenasParaRecolha = Nothing
Set DocumentoDestino = Nothing
End Sub

Open in new window

0
Armando Vilela Baiões Self-taughtAuthor Commented:
Working code for this question. If anyone is trying to do the same, here goes:

sub to loop over form with the OLE word docs listed:

Private Sub Command61_Click()
Dim ServerWordFS As Object
Set ServerWordFS = CreateObject("Word.Application")


Dim FirstTime As Integer
FirstTime = 1

For LoopCenasKit = 1 To Forms!frmFScomposicao!subfrmFScenas![tiroliro]
If FirstTime = 1 Then
Me.FirstTimeBox = FirstTime
Forms!frmFScomposicao!subfrmFScenas.SetFocus
Forms!frmFScomposicao!subfrmFScenas![EQUIPA].SetFocus

DoCmd.RunCommand acCmdRecordsGoToFirst


Call StartKit

DoCmd.RunCommand acCmdRecordsGoToNext
FirstTime = FirstTime + 1
Else

Call AddKit

DoCmd.RunCommand acCmdRecordsGoToNext
FirstTime = FirstTime + 1
End If
Next LoopCenasKit

ServerWordFS.Quit
End Sub

Open in new window



2 subs to create word doc wherever you want:

Public Sub StartKit()

Dim oAPP As Object
Dim oDoc As Word.Document
Dim cenaspararecolha As Object

        Set oAPP = CreateObject(Class:="Word.Application")
        With oAPP
        .Visible = True
        
        Set oDoc = .Documents.Add
        oDoc.SaveAs "C:\Fserv\FolhaServiço", wdFormatDocument
        End With
        
Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].SetFocus
     Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].Action = acOLEActivate
    Set cenaspararecolha = Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].Object.Application.WordBasic
            With cenaspararecolha
            Selection.WholeStory
            Selection.Copy
            End With

Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].Action = acOLEClose

With oAPP
.Selection.PasteSpecial DataType:=wdPasteRTF
End With

oDoc.Save
oDoc.Activate
oDoc.Close
oAPP.Quit
End Sub

Public Sub AddKit()

Dim oAPP As Object
Dim oDoc As Word.Document
Dim cenaspararecolha As Object


        Set oAPP = CreateObject(Class:="Word.Application")
        With oAPP
        .Documents.Open Filename:="C:\Fserv\FolhaServiço.doc"
        .Visible = True
        .Selection.EndKey wdStory
        .Selection.InsertBreak
        End With

Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].SetFocus
     Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].Action = acOLEActivate
    Set cenaspararecolha = Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].Object.Application.WordBasic
            With cenaspararecolha
            Selection.WholeStory
            Selection.Copy
            End With
Forms!frmFScomposicao!subfrmFScenas![Prod_Cena_Guiao].Action = acOLEClose

With oAPP
.Selection.PasteSpecial DataType:=wdPasteRTF
Set oDoc = .ActiveDocument
oDoc.Save
End With

oDoc.Close
oAPP.Quit
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Armando Vilela Baiões Self-taughtAuthor Commented:
Working Code
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.