Results 1 to 2 of 2
  1. #1
    KLahvic is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    2

    Help With Runtime Error 4248

    I have code on the on click command to trigger a custom form template generated by Word to be populated by certain fields in my database. When I click the button, I get a run time error 4248 saying "This command is not available because no document is open" I will post my code below, can someone have a look and help me figure this one out?

    Code:
    Private Sub Mergebttn_Click()
    'Declare Variables for storing strings
    Dim AddyLineVar As String, SalutationVar As String
    If IsNull([LastName]) Then
        AddyLineVar = [VendorName]
    Else
        AddyLineVar = [FirstName] & " " & [LastName] & " " & [Suffix] & " " & [Title]
        SalutationVar = [FirstName] & " " & [LastName]
    End If
    AddyLineVar = AddyLineVar & vbCrLf & [Address1]
    If Not IsNull([Address2]) Then
        AddyLineVar = AssyLineVar & vbCrLf & [Address2]
    End If
    AddyLineVar = AddyLineVar & vbCrLf & [City] & ", "
    AddyLineVar = AddyLineVar & [State] & "  " & [Zip]
    Dim Wrd As New Word.Application
    Set Wrd = CreateObject("Word.Application")
    Dim MergeDoc As String
    MergeDoc = Application.CurrentProject.Path
    MergeDoc = MergeDoc & "\EchoDomestic.dotx"
    Wrd.Visible = True
    With Wrd.ActiveDocument.Bookmarks
        .Item("VendorName").Range.Text = AddyLineVar
        .Item("TodaysDate").Range.Text = Date
        .Item("ContactPerson").Range.Text = SalutationVar
    End With
    Wrd.ActiveDocument.PrintOut
    Wrd.ActiveDocument.Close wdDoNotSaveChanges
    End Sub
    When I debug, the line that highlights is this:

    Code:
    With Wrd.ActiveDocument.Bookmarks
    Hopefully someone can help me through, if you need more information let me know. Thank you all so much.



    Ken

  2. #2
    c_smithwick is offline Underpaid Programmer
    Windows 7 Access 2003
    Join Date
    Jan 2010
    Location
    Lakeside, CA
    Posts
    49
    You need to add the following line to open the document first in your Word Application

    Code:
    Wrd.Documents.Open MergeDoc

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

Similar Threads

  1. Runtime help! What am I to do?
    By shesgone in forum Access
    Replies: 2
    Last Post: 04-04-2010, 11:19 PM
  2. Where is my runtime program?
    By shesgone in forum Access
    Replies: 2
    Last Post: 04-02-2010, 07:27 PM
  3. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 PM
  4. 2003 Runtime
    By miclar99 in forum Access
    Replies: 4
    Last Post: 01-12-2010, 05:30 PM
  5. Replies: 5
    Last Post: 08-05-2009, 04:07 PM

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