Results 1 to 5 of 5
  1. #1
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100

    How to fix wrong number of arguments with multiple functions?

    So I have the expression below that returns the "The expression you entered has a function containing the wrong number of arguments". I have trouble once I have more than two Functions. I get lost on where the parenthesis go.

    Code:
    Format(DateAdd(Left([Date],8),'h',4,[Date],"Long Time"))
    Any tips? Also, for future purposes, how do I know where the parenthesis go? The functions inside get calculated first right?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Build it from the inside out.
    Plus parameters/arguments must be in the correct order?

    Code:
    ? Left(Date(),8)
    05/11/20
    ? dateadd("h",4,Left(Date(),8))
    05/11/2020 04:00:00 
    ? Format(dateadd("h",4,Left(Date(),8)),"Long Time")
    04:00:00
    I'm not sure that was the result you expected?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Is Date a field in your table (it is a reserved word in Access and you shouldn't use it like that) or do you try to use today's date in which case you would need the built in function Date()?

    If you look at the DateAdd (https://support.microsoft.com/en-us/...4-61e8c57afc19) you'll see in your expression you seem to have the first two argument reversed, you start with the interval ("h") then the number to add (4) then the starting date value ([Date] or Date() if you want today's date). Note that if adding hours to today's date you might want to switch to Now() instead of Date() as the latest does not have a time component.

    You might want to show us an example of the [Date] field as I am not sure what the first 8 characters are (your Left() function).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    I just put date as an example - the field is named something else. The Date Function is hours, minutes, seconds and milliseconds. The Left, 8 removes the milliseconds.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Then it should be something like this:

    Format(DateAdd("h",4,CDate(Left([YourDateField],8))),"Long Time")

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Expression Builder - wrong number of arguments
    By Frannilea in forum Access
    Replies: 1
    Last Post: 08-23-2020, 04:41 AM
  2. Wrong number of arguments
    By Perfac in forum Programming
    Replies: 10
    Last Post: 05-20-2020, 05:52 PM
  3. function has the wrong number of arguments
    By Darla in forum Programming
    Replies: 6
    Last Post: 02-09-2017, 02:03 PM
  4. Replies: 3
    Last Post: 09-09-2015, 11:26 AM
  5. Replies: 3
    Last Post: 02-12-2014, 03:36 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