Results 1 to 5 of 5
  1. #1
    awaiskazmi is offline Novice
    Windows 10 Access 2007
    Join Date
    Oct 2017
    Location
    Pakistan
    Posts
    3

    Need help to resolve - Error appears "Object Required"

    When i use this code i get error "Object Required"


    Private Sub Command12_Click()
    Dim cn As ADODB.Connection
    Set rs = New ADODB.Recordset
    On Error GoTo errorhandler


    Set cn = New ADODB.Connection


    Set rs = New ADODB.Recordset
    rs.ActiveConnection = CurrentProject.Connection
    rs.Open ("select * from MySelectedObservations")


    Dim objWord As Word.Application
    Dim pathgetter As String
    Dim doc As Word.Document
    Dim WordHeaderFooter As HeaderFooter
    Dim filepath As String
    Set objWord = CreateObject("Word.Application")


    pathgetter = DLookup("Word_Path_Field", "WORD_PATH_TBL", "Serial = 1")
    filepath = "" & pathgetter & "\Observations " & Format(Now(), "dd-mm-yyyy") & ".docx"


    With objWord
    .Visible = True


    Set doc = .Documents.Open(filepath)
    End With


    With objWord.Selection



    .Font.Name = "Times New Roman"
    .Font.Size = 10
    .Font.TextColor = vbBlack
    .Font.Bold = True
    .Font.Underline = wdUnderlineSingle
    '.Font.Bold = True


    .TypeText Observation_Heading.Value
    .TypeText ":"
    .TypeParagraph


    .Font.Name = "Times New Roman"
    .Font.Size = 10
    .Font.TextColor = vbBlack
    .Font.Bold = False
    .Font.Underline = wdUnderlineNone
    .TypeText Observation_Details.Value
    .TypeParagraph
    .TypeParagraph

    .Font.Name = "Times New Roman"
    .Font.Size = 10
    .Font.TextColor = vbBlack
    .Font.Bold = True
    .Font.Underline = wdUnderlineNone

    .TypeText "Risk Implication: "

    .Font.Name = "Times New Roman"
    .Font.Size = 10
    .Font.TextColor = vbBlack
    .Font.Bold = False
    .Font.Underline = wdUnderlineNone

    .TypeText Risk_Implication.Value
    .TypeParagraph

    .Font.Name = "Times new Roman"
    .Font.Size = 10
    .Font.TextColor = vbBlack
    .Font.Bold = True
    .Font.Underline = wdUnderlineNone


    .TypeText "Risk Category: "
    .TypeParagraph

    .Font.Name = "Times New Roman"
    .Font.Size = 10
    .Font.TextColor = vbBlack
    .Font.Bold = False
    .Font.Underline = wdUnderlineNone

    .TypeText Risk_Category.Value
    .TypeParagraph

    .Font.Name = "Times New Roman"
    .Font.Size = 10
    .Font.TextColor = vbBlack
    .Font.Bold = True
    .Font.Underline = wdUnderlineNone


    .TypeText "Branch Remarks: "
    .TypeParagraph
    .TypeParagraph


    End With


    doc.Save
    doc.Activate





    errorhandler:
    MsgBox Err.Description


    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    On what line? Disable the error handler for debugging - comment the On Error line.

    Please post lengthy code between CODE tags to retain indentation and readability.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    awaiskazmi is offline Novice
    Windows 10 Access 2007
    Join Date
    Oct 2017
    Location
    Pakistan
    Posts
    3
    error comes at line

    Set doc = .Documents.Open(filepath)

    Runtime error 462 The remote server machine does not exist

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Perhaps the variable filepath is not getting the correct value. When the debugger stops on that line, what is the value? Does document in that path actually exist?

    I tested code with static path/filename and it works. Here's the simple code I tested.

    Code:
    Dim objWord As Word.Application
    Dim doc As Word.Document
    Set objWord = CreateObject("Word.Application")
    With objWord
        .Visible = True
        Set doc = .Documents.Open("C:\Users\June\Keyboard.docx")
    End With
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    awaiskazmi is offline Novice
    Windows 10 Access 2007
    Join Date
    Oct 2017
    Location
    Pakistan
    Posts
    3
    boss i did it ............ project successfully completed

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-12-2017, 04:29 PM
  2. Replies: 7
    Last Post: 07-10-2015, 01:02 PM
  3. Replies: 3
    Last Post: 02-06-2015, 03:22 PM
  4. Replies: 12
    Last Post: 08-07-2014, 10:28 AM
  5. Replies: 1
    Last Post: 03-14-2013, 12:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums