Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2011, 04:18 AM
Registered User
 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Runtime Error 462

Hi everyone,
I have problem with open Word document from Access. Firs time everything is ok, and then on the middle of code it give me a message: Runtime Error 462, The remote server machine does not exist or is unavailable.
here it is:
Public Sub Command60_Click()
On Error GoTo Err_Command60_Click

Dim oApp As Object
Dim doc As Object
Dim lokacija As String


lokacija = Application.CurrentProject.Path & "\putni_list.dot"

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Set doc = oApp.Documents.Open(lokacija, , True)

With doc
...

Dim lavSQL As String
Dim lokSQL As String
Dim osoSQL As String

...

Dim recset As ADODB.Recordset
Set recset = New ADODB.Recordset
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
Dim row_num As Integer
Dim col_num As Integer
Dim odobrenje As Integer
odobrenje = Me.ID.Value

recset.Open "Select ...", _
conn, adOpenKeyset, adLockOptimistic
recset.MoveLast
recset.MoveFirst
.Bookmarks("lokomotiva").Select
.Tables.Add Range:=Selection.Range, NumRows:=recset.RecordCount, NumColumns:=recset.Fields.Count <=broken cod onn second open, err 462
For row_num = 1 To recset.RecordCount
For col_num = 1 To recset.Fields.Count
.Tables(.Tables.Count).Cell(row_num, col_num).Select
Selection.TypeText recset.Fields(col_num - 1)
Next col_num
recset.MoveNext
Next row_num


.SaveAs FileName:=Application.CurrentProject.Path & " " & Me.vlak.Value & " " & Me.Datum.Value & ".doc"

End With

recset.Close
Set recset = Nothing
conn.Close
Set doc = Nothing
Set oApp = Nothing


Exit_Command60_Click:
Exit Sub
Err_Command60_Click:
MsgBox Err.Description
Resume Exit_Command60_Click

End Sub
Please help.
 
Old September 20th, 2011, 03:21 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

Please post all your VBA code.

I think you have left out parts that that are related to the issue.

From what you posted I I spotted one:

Code:
Selection.TypeText recset.Fields(col_num - 1)
looks like it is missing the leading . for the With Doc

Code:
.Selection.TypeText recset.Fields(col_num - 1)

The may be other ssues. Hard to say for sure with seeing all the VBA code.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
 
Old September 20th, 2011, 04:43 PM
Registered User
 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was tries with ".Selection..." but it wasn't work. Insert message "Object doesn't support this property or method"
Here is all code:
Public Sub Command60_Click()
On Error GoTo Err_Command60_Click

Dim oApp As Object
Dim doc As Object
Dim lokacija As String


lokacija = Application.CurrentProject.Path & "\putni_list.dot"

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Set doc = oApp.Documents.Open(lokacija, , True)

With doc
.formfields("vlak").result = CStr(Me.vlak.Value)
.formfields("kolodvor1").result = CStr(Me.Combo23.Column(1))
.formfields("kolodvor2").result = CStr(Me.Combo23.Column(1))
.formfields("kolodvor3").result = CStr(Me.Kombinirani20.Column(1))
.formfields("dana").result = CStr(Me.Datum.Value)

Dim lavSQL As String
Dim lokSQL As String
Dim osoSQL As String

lokSQL = "SELECT t_dionice.dionica_pruge, tblVlak.lokomotiva, tblStatus.status, tblVlak.strojovodja, tblRadnoMjesto.radno_mjesto, tblVlak.relacija, tblVlak.osovine, tblVlak.bruto, tblVlak.duljina, tblVlak.SKM, tblVlak.postotak, ((tblVlak.SKM*tblVlak.postotak)/100) AS PKM, tblVlak.IDPutniList" _
& "FROM tblStatus INNER JOIN (tblRadnoMjesto INNER JOIN (t_dionice INNER JOIN (PutniList INNER JOIN tblVlak ON PutniList.ID = tblVlak.IDPutniList) ON t_dionice.ID = tblVlak.relacija) ON tblRadnoMjesto.ID = tblVlak.IDRadnoMjesto) ON tblStatus.ID = tblVlak.IDStatus;"

osoSQL = "SELECT t_dionice.dionica_pruge, tblOsoblje.Ime, tblDomicil.domicil, tblRadnoMjesto.radno_mjesto, tblOsoblje.IDPutniList" _
& "FROM t_dionice INNER JOIN (tblRadnoMjesto INNER JOIN (tblDomicil INNER JOIN tblOsoblje ON tblDomicil.ID = tblOsoblje.domicil) ON tblRadnoMjesto.ID = tblOsoblje.radno_mjesto) ON t_dionice.ID = tblOsoblje.relacija;"


lavSQL = "SELECT t_pruge.[šifra pruge], t_dionice.dionica_pruge, tbl_lagane_voznje.od_km & " + " & tbl_lagane_voznje.od_m AS Expr1, tbl_lagane_voznje.do_km & " + " & tbl_lagane_voznje.do_m AS Expr2, tbl_lagane_voznje.vmax, tbl_lagane_voznje.datum_kraja, tbl_lagane_voznje.datum_pocetka" _
& "FROM (t_dionice INNER JOIN tbl_lagane_voznje ON t_dionice.ID = tbl_lagane_voznje.dionica) INNER JOIN t_pruge ON tbl_lagane_voznje.pruga = t_pruge.ID" _
& "WHERE (((tbl_lagane_voznje.datum_kraja) Is Null))" _
& "ORDER BY tbl_lagane_voznje.od_km;"

Dim recset As ADODB.Recordset
Set recset = New ADODB.Recordset
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
Dim row_num As Integer
Dim col_num As Integer
Dim odobrenje As Integer
odobrenje = Me.ID.Value

recset.Open "Select dionica_pruge, lokomotiva, status, strojovodja, radno_mjesto From lokSQL Where IDPutniList= " + CStr(Me.ID.Value), _
conn, adOpenKeyset, adLockOptimistic
recset.MoveLast
recset.MoveFirst
.Bookmarks("lokomotiva").Select
.Tables.Add Range:=Selection.Range, NumRows:=recset.RecordCount, NumColumns:=recset.Fields.Count
For row_num = 1 To recset.RecordCount
For col_num = 1 To recset.Fields.Count
.Tables(.Tables.Count).Cell(row_num, col_num).Select
Selection.TypeText recset.Fields(col_num - 1)
Next col_num
recset.MoveNext
Next row_num
recset.Close

recset.Open "Select dionica_pruge, Ime, domicil, radno_mjesto From osoSQL Where IDPutniList= " + CStr(Me.ID.Value), _
conn, adOpenKeyset, adLockOptimistic
If recset.RecordCount = 0 Then
.formfields("osoblje").result = CStr("-")
Else
recset.MoveLast
recset.MoveFirst
.Bookmarks("osoblje").Select
.Tables.Add Range:=Selection.Range, NumRows:=recset.RecordCount, NumColumns:=recset.Fields.Count
For row_num = 1 To recset.RecordCount
For col_num = 1 To recset.Fields.Count
.Tables(.Tables.Count).Cell(row_num, col_num).Select
Selection.TypeText recset.Fields(col_num - 1)
Next col_num
recset.MoveNext
Next row_num
End If
recset.Close


recset.Open "Select dionica_pruge, Expr1, Expr2, vmax From DS_SM", _
conn, adOpenKeyset, adLockOptimistic

If recset.RecordCount = 0 Then
.formfields("tablica").result = CStr("-")
Else
recset.MoveLast
recset.MoveFirst
.Bookmarks("tablica").Select
.Tables.Add Range:=Selection.Range, NumRows:=recset.RecordCount, NumColumns:=recset.Fields.Count
For row_num = 1 To recset.RecordCount
For col_num = 1 To recset.Fields.Count
.Tables(.Tables.Count).Cell(row_num, col_num).Select
Selection.TypeText recset.Fields(col_num - 1)
Next col_num
recset.MoveNext
Next row_num
End If
.SaveAs FileName:=Application.CurrentProject.Path & " " & Me.vlak.Value & " " & Me.Datum.Value & ".doc"

End With
recset.Close
Set recset = Nothing
Set doc = Nothing
oApp.Quit



Exit_Command60_Click:
Exit Sub
Err_Command60_Click:
MsgBox Err.Description
Resume Exit_Command60_Click

End Sub

Before insert table my code work without errors, but after I find this code in book and prepare for my needs I have problem.
Thanks for your help, I'm advance beginner in access

Last edited by mobydick; September 23rd, 2011 at 02:40 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft VBScript runtime error '800a000d' error futurehype Classic ASP Professional 20 May 23rd, 2011 10:47 PM
Chapter 13,page 462 Masego.Moikanyang BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 25 April 16th, 2011 01:17 PM
hi i got runtime error 13 Type Mismatch error sriharsha345 Access VBA 2 February 21st, 2008 09:30 AM
Error # 462 - Remote Server does not exist or is u doncar38 Word VBA 3 January 17th, 2008 08:04 AM
Error 462 : Remote server doesn't exist ldk2004 BOOK: Expert One-on-One Access Application Development 0 December 17th, 2004 01:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.