Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Sorry for the delay, as normal i had something else to do yesterday.



    Access - import to word test.zip

    Ive removed 99% of the database content leaving only whats relevent and a few test lines.

    Please see attached.

  2. #17
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    I can't see why it doesn't see the form criteria, however if you create the query on the fly based on the current record it works; (The query does, it bombs out as It can't find the word doc...)
    Code:
    
    Private Sub Command92_Click()
    
    
    
    
        '-----------------Set up word document to use recordset ------------------
        Dim wrdApp As New Word.Application
        Dim wrdDoc As Word.Document
        Dim filepath As String
        Dim docFile As String
        Dim rst As DAO.Recordset
        '-----------------Set up word document to use recordset ------------------
    
    
        '                    --------------------------
    
    
        '-----------------define bookmark variables as range -----------------
        Dim test As Word.Bookmarks
        '-----------------define bookmark variables as range ------------------
    
    
    
    
        '------------------ define query -----------------------------
        Dim db As Database
        Dim sSql As String
    
    
        Set db = CurrentDb
    
    
        sSql = "SELECT SiteT.Site_ID, SiteT.Site_Name, SiteT.Asset_Type, SiteT.Address_1, SiteT.Address_2, SiteT.Address_3, SiteT.Postcode, ClientT.Company_Name, ClientT.Company_ID, HospitalT.Hospital_Name, HospitalT.Hospital_Postcode, HospitalT.Hospital_Address, HospitalT.Hospital_Telephone, SiteT.lat, SiteT.long "
        sSql = sSql & "FROM HospitalT INNER JOIN (ClientT INNER JOIN SiteT ON ClientT.Company_ID = SiteT.Site_Owner) ON HospitalT.Hospital_ID = SiteT.Hospital_ID "
        sSql = sSql & "WHERE [SiteT].[Site_ID] = " & Me.Site_ID & " "
        sSql = sSql & "ORDER BY SiteT.Site_Name;"
    
    
        Set rst = db.OpenRecordset(sSql)
    
    
        Debug.Print rst.Fields(1), rst.Fields(2)
    
    
        filepath = "C:\Users\ah\Desktop\RAMS AUTOMATION\RAM.docm"
    
    
    
    
    
    
    
    
        Set wrdApp = CreateObject("Word.Application")
        wrdApp.Visible = True
    
    
        Set wrdDoc = wrdApp.Documents.Open(filepath)
    
    
        With wrdDoc
    
    
            wrdApp.ActiveDocument.Bookmarks("test").Select
            wrdApp.Selection.Text = rst("Site_ID") & " " & rst("Site_Name")
    
    
        End With
        Set rst = Nothing
    
    
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #18
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    according to Andre on stack overflow:

    Code:
    A parameter like [Forms]![SurveyRegister_frm]![SurveyID] doesn't get evaluated automatically if you open a recordset in VBA.
    I was trying to implement the function provided by him but I was stuck. Your code works perfect, Im sure the SQL is easy enough to understand if I take some time to work it out.

    I'm actually quite terrible at VBA the only reason I have a database/other macros is becauseof my persistance and mainly the help from everyone here. So, Once again, thanks to everyone looking into this.

    This will save hours of time and allow me to build on it to manage the whole project/ risks through the database.

  4. #19
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Understanding it was much easier than expected. Haha. Appreciate you doing that for me.

  5. #20
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    No problem - glad to have helped.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Too Few Parameters. Expected 1
    By flamesofdoom in forum Programming
    Replies: 1
    Last Post: 02-15-2013, 02:23 PM
  2. too few parameters; expected 2
    By slimjen in forum Forms
    Replies: 13
    Last Post: 07-26-2012, 02:42 PM
  3. Too few parameters. expected 1.
    By seth1685 in forum Programming
    Replies: 1
    Last Post: 01-11-2012, 08:08 AM
  4. Too few parameters expected 4
    By forestgump in forum Programming
    Replies: 1
    Last Post: 04-15-2011, 09:10 AM
  5. Too few parameters. Expected 2.
    By PPCMIS2009 in forum Access
    Replies: 0
    Last Post: 01-28-2009, 01:02 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