Results 1 to 9 of 9
  1. #1
    rywello is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2018
    Posts
    14

    Listbox Issues

    I am trying to send the contents of a listbox through email. The listbox is based on a query that works fine. The email function worked properly until I added a date field in the query with a where clause that is based on 2 date text boxes on the main form. I am getting the error Too few Parameters expected 2. I am not sure how to proceed. I have attached a copy of the database. When you go into frmtimesheet, you select the employee and the start and end time and using the first and second tabs you can see their shifts and differentials. In the third tab you can email the OT. When I click the Email OT button, that is where I get the error.



    Any, help is appreciated. Thanks!
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Haven't run the code, but OpenRecordset can't resolve form references, and the query has 2. Simplest solution is to wrap each form reference in the Eval() function.

    Eval("Forms!...")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Ah Paul's solution somewhat simpler than mine...

    I went back to the original query and used that ... doh!

    Code:
    If strList <> "" Then
                strList = Left(strList, Len(strList) - 1)
                strList = "(" & strList & ")"
                strSQL = "SELECT DISTINCT EMPLOYEES.EMP_NB, EMPLOYEES.EMPLOYEE, [TheTimeQuery_No Calculations].Schedule_ID, Sum([TheTimeQuery_No Calculations].DT_Hours) AS SumOfDT_Hours, Sum([TheTimeQuery_No Calculations].[Afternoon Hours]) AS [SumOfAfternoon Hours], Sum([TheTimeQuery_No Calculations].[Night Hours]) AS [SumOfNight Hours], Sum([TheTimeQuery_No Calculations].[OT Hours]) AS [SumOfOT Hours], Sum([TheTimeQuery_No Calculations].UnAfternoonSD) AS SumOfUnAfternoonSD, Sum([TheTimeQuery_No Calculations].UnOvernightSD) AS SumOfUnOvernightSD"
                strSQL = strSQL & " FROM EMPLOYEES INNER JOIN [TheTimeQuery_No Calculations] ON EMPLOYEES.schedule_id = [TheTimeQuery_No Calculations].Schedule_id"
                strSQL = strSQL & " WHERE [EMP_NB] IN " & strList & " "
                strSQL = strSQL & " AND [TheTimeQuery_No Calculations].WorkDay Between #" & Nz(Format([Forms]![frmtimesheet]![txtPeriod1], "yyyy/mm/dd"), 1 / 1 / 1000) & "# And #" & Nz(Format([Forms]![frmtimesheet]![TxtPeriod2], "yyyy/mm/dd", 1 / 1 / 3000)) & "#"
                strSQL = strSQL & " GROUP BY EMPLOYEES.EMP_NB, EMPLOYEES.EMPLOYEE, [TheTimeQuery_No Calculations].Schedule_ID"
                strSQL = strSQL & " ORDER BY EMPLOYEES.EMPLOYEE "
    
    
                '(send e-mail)
            Else
    I doubt the Nz portion will work as access is treating them as a calculation, rather than a date string.
    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 ↓↓

  4. #4
    rywello is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2018
    Posts
    14
    I tried to wrap it and I get the error...."The expression you entered contains the wrong number of arguments.

    Between Eval([Forms]![frmtimesheet]![txtPeriod1],#1/1/1000#) And Eval([Forms]![frmtimesheet]![TxtPeriod2],#1/1/3000#)

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Well, you've mixed the Eval and Nz functions. Note the quotes in my example; they weren't for show.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    rywello is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2018
    Posts
    14
    Like this...Between Eval("[Forms]![frmtimesheet]![txtPeriod1]",#1/1/1000#) And Eval("[Forms]![frmtimesheet]![TxtPeriod2]",#1/1/3000#)

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You're still mixing the functions; the Eval() function has no place for a date.

    Nz(Eval("[Forms]![frmtimesheet]![txtPeriod1]"),#1/1/1000#)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    rywello is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2018
    Posts
    14
    Ahh ok...thanks so much for your help!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. issues with listbox display from query
    By epardo87 in forum Forms
    Replies: 3
    Last Post: 01-16-2017, 12:05 PM
  2. Replies: 1
    Last Post: 01-31-2015, 09:03 PM
  3. Replies: 2
    Last Post: 03-23-2014, 06:50 AM
  4. Replies: 1
    Last Post: 09-10-2012, 11:21 PM
  5. Replies: 1
    Last Post: 07-26-2012, 11:45 AM

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