Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    too few parameters expected 1 with criteria in query.

    I have some code that will place a field from a query into a word document. I can not get this to work how I want with the query I need.



    I get this error when using the query with filtered results:

    Code:
    too few parameters expected 1
    The criteria im using is:

    Code:
    [Forms]![SiteFullListF]![site_ID]
    If i remove this criteria then the query returns every record BUT the code works to add feilds to the word document.

    (When i say works what I mean is.. It will do the first record in the list and then error because the template docuement is already open.)

    So i need to filter query results whilst being able to use the code.

    Any suggestions are appreciated.

    Thanks, Andy

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Too few parameters can often indicate a spelling error.

    You haven't given us a lot of info, but here's a guess to consider.

    Sometimes you have conditional logic regarding another application ( eg excel, outlook)

    Code is along this line( air code)

    Code:
    if someFlag then
      createObject.... excel app --------------------->create an instance
    else
      getobject.....  excel app -----------------------> instance exists so use it 
    end if

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Hi Orange, when troubleshooting I've edited the query to contain only one field for testing (one table also).

    In access all results are shows with the criteria field being empty.. with the criteria being used then only the correct record is shown. So the query is correct with no spelling errors.

    this is the whole code im using:

    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 -----------------------------
    Set rst = CurrentDb.OpenRecordset("SITE_RAMS")
    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
    which generates the error on this line: (ONLY WHEN USING CRITERIA IN QUERY)

    Code:
    Set rst = CurrentDb.OpenRecordset("SITE_RAMS")

    As I said earlier. If I remove the criteria then the word document will populate correctly for the first record in the recordset.

    I dont wish to do this for multiple records anyway so it's just the problem with using criteria.

    I'm not sure what you mean with your sugestion or if it applies still after my explination. I guess a way around this could be to use the query itself as a table in a new query and then use that query as a recordset... I can give that a go and report back.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Andy,
    No, my suggestion doesn't apply.

    Good luck.

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Sadly using this query as a table in query builder doesnt rectify the issue. I'm at a loss..

    I dont want to give up because everything seems to be working fine except this error. Could you suggest anything else?

    Andy

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    the SQL causing issue is:

    Code:
    WHERE (((SiteT.Site_ID)=[Forms]![SiteFullListF]![site_ID]))
    this works within access for everything else i would do normally.

    I have found this online:

    https://stackoverflow.com/questions/...ecordset-issue

    It doesnt mean much to me im trying to work it out.

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Is the form with that control actually open when you are calling this code?
    It needs to be.
    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 ↓↓

  8. #8
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Yes It's a button on the form I'm pressing.

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Couple of shot in the dark ideas.
    1. Is SiteFullListF a subform? If so, and the query is being built behind the main form, you need to adjust the WHERE code to account for the control holding the subform.
    2. Try WHERE (((SiteT.Site_ID)=[Forms]![SiteFullListF].[site_ID]))
    3. I assume Site_ID is numeric, if not then
    WHERE SiteT.Site_ID='" & [Forms]![SiteFullListF].[site_ID] & "'"

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Andy
    Can you show us the whole query for
    "SITE_RAMS"?

  11. #11
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Dave, Thanks for the replies.

    I was really hopeful, especially about sugestion 2. Sadly nothing worked. As a note: here is no sub form.

    Ill have a go setting up the function in the link I posted earlier. (took me a while to see what the sugestion actually was)
    from the link:
    Code:
    A parameter like [Forms]![SurveyRegister_frm]![SurveyID] doesn't get evaluated automatically if you open a recordset in VBA.
    I'll update shortly.

  12. #12
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Orange:

    Code:
    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
    FROM HospitalT INNER JOIN (ClientT INNER JOIN SiteT ON ClientT.Company_ID = SiteT.Site_Owner) ON HospitalT.Hospital_ID = SiteT.Hospital_ID
    WHERE ((([SiteT].[Site_ID])=[Forms]![SiteFullListF].[site_ID]))
    ORDER BY SiteT.Site_Name;
    This is the whole query SQL.

  13. #13
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Just to provide some context, Ill be placing bookmarks in a risk assesement document. The user can go onto the database, select the location of works and itwill then produce a document as a basis to work on. The user will still need to add methodology but it would allow us to improve accuracy and save time.

  14. #14
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Sadly I've been roped into doing some other works. I'll work on adding the other code on the weekend and update on monday. I'm assuming it will be okay once/if I understand it.

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Andy,
    Is it possible to provide a copy of database with just a few dummy records eg Porky Pig, Donald Duck --Wales General Hospital sort of thing. Enough dummy data to "test".
    It's failing in Access, right ----doesn't get to Word with the criteria?

    It certainly seems it is not getting a value from the form.
    Anyway you can try Debug.Print
    [Forms]![SiteFullListF].[site_ID]
    just to see what Access thinks???

Page 1 of 2 12 LastLast
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