Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2014
    Posts
    4

    MS access "No values given for one or more parameters"

    i have an ongoing error in ms access vba, being pretty new to the app i am stuck, i have a split database where in i am trying to execute a query in vba but it is throwing the error"No values found for one or more given parameter" however when i debug.print the query and run in ms access it works fine,



    below is the query, can you help:

    qry = "SELECT * FROM Core"
    qry1 = qry & " WHERE (((Core.Activity='" & UCase([Forms]![frmReports]![cmbrptactivity]) & "') AND (Core.Unit='" & UCase([Forms]![frmReports]![cmbunit]) & "') AND (Core.Dt_Upload Between #" & [Forms]![frmReports]![txtDate1] & "# And #" & [Forms]![frmReports]![txtDate2] & "#)))"
    qry2 = qry1 & " OR (((Core.Activity='" & UCase([Forms]![frmReports]![cmbrptactivity]) & "') AND (([Forms]![frmreports]![cmbunit]) Is Null) AND (Core.Dt_Upload Between #" & [Forms]![frmReports]![txtDate1] & "# And #" & [Forms]![frmReports]![txtDate2] & "#)))"
    qry3 = qry2 & " OR ((((Core.Unit)='" & UCase([Forms]![frmReports]![cmbunit]) & "') AND (([Forms]![frmreports]![cmbrptactivity]) Is Null) AND ((Core.Dt_Upload) Between (#" & [Forms]![frmReports]![txtDate1] & "#) And (#" & [Forms]![frmReports]![txtDate2] & "#))))"
    qry4 = qry3 & " OR (((([Forms]![frmreports]![cmbunit]) Is Null) AND (([Forms]![frmreports]![cmbrptactivity]) Is Null) AND ((Core.Dt_Upload) Between (#" & [Forms]![frmReports]![txtDate1] & "#) And (#" & [Forms]![frmReports]![txtDate2] & "#))))"

    rs.Open qry4, cn, adOpenKeyset, adLockOptimistic

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Is Core a table or a query with dynamic parameters?
    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
    Join Date
    Oct 2014
    Posts
    4
    Core is a master table with all the data, there is user form frmReports also acting as a search form. I am allowing users to pass either one or multiple parameters to refine the data, once the data is filtered i would be inputting this data to a new temp table which inturn will populate the report. This is the approach i am following.If you have a better approach it will be highly appreciated. The above mentioned query works fine if i execute in ms access but not if i execute it through vba.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Not sure what this criteria does for filtering records nor why it is within quote marks. Maybe this is cause of the issue. I can't see anything else.

    " OR (((([Forms]![frmreports]![cmbunit]) Is Null) AND (([Forms]![frmreports]![cmbrptactivity]) Is Null) ... "
    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
    Join Date
    Oct 2014
    Posts
    4
    i am checking for three fields
    1, if activity is not selected
    2, if unit is not selected
    3, if only date is selected
    this is the third case... the only thing that makes me curious is that this qry works perfectly fine in access but has issues only when run through vba

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Did you try pulling the control references out of the quote marks and concatenating?
    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.

  7. #7
    Join Date
    Oct 2014
    Posts
    4
    Quote Originally Posted by June7 View Post
    Did you try pulling the control references out of the quote marks and concatenating?
    Yes i did, but it aint work getting me on my nerves.... i will try to figure out some other workaround but this seems doable, just that i am missing on some syntax or reference i guess....

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    I've never tried to build a query (Access object or VBA) that has that sort of parameter. Apparently the VBA construct is just seeing a string of characters and not treating it as reference to a form control if within quote marks so seems the concatenation should work which should evaluate to True/False.

    Maybe:

    IsNull([Forms]![frmreports]![cmbunit]) AND IsNull([Forms]![frmreports]![cmbrptactivity])


    I build the WHERE clause conditionally. Review http://allenbrowne.com/ser-62code.html
    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.

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

Similar Threads

  1. Replies: 12
    Last Post: 05-23-2013, 10:56 AM
  2. Replies: 13
    Last Post: 01-30-2013, 03:05 PM
  3. Replies: 2
    Last Post: 11-14-2012, 04:47 PM
  4. Automating "Append" Query with Parameters
    By Monterey_Manzer in forum Queries
    Replies: 1
    Last Post: 10-04-2012, 12:00 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