Results 1 to 9 of 9
  1. #1
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    109

    Run-time error 3075

    I wonder if you would be willing to help me one more time with the database I inherited
    I ma trying to create table, add the values and sum totals on click event. Everything works up to summing then I am getting the message:
    Run-time error 3075
    Syntax error (missing operator) in query expression
    ‘Sum(tblCWP_PercentComplete.3DCadd complete)’.

    Would be the number "3" which stops me executing the command and if so how to fix it.
    Below is part of the code which doesn't work.
    Thanks

    ' Add Totals line at the bottom
    strsql = "SELECT Sum(tblCWP_PercentComplete.Total) AS SumOfTotal, Sum(tblCWP_PercentComplete.Assembled) AS SumOfAssembled, " & _
    "Sum(tblCWP_PercentComplete.Reset) AS SumOfReset, Sum(tblCWP_PercentComplete.ReDesignRequired) AS SumOfReDesignRequired, " & _
    "Sum(tblCWP_PercentComplete.DesignComplete) AS SumOfDesignComplete, Sum(tblCWP_PercentComplete.3DCaddComplete) AS SumOf3DCaddComplete " & _
    "Sum(tblCWP_PercentComplete.ReCaddRequired) AS SumOfReCaddRequired, Sum(tblCWP_PercentComplete.2DCaddComplete) AS SumOf2DCaddComplete " & _
    "Sum(tblCWP_PercentComplete.QCReviewComplete) AS SumOfQCReviewComplete, Sum(tblCWP_PercentComplete.CheckingComplete) AS SumOfCheckingComplete " & _
    "Sum(tblCWP_PercentComplete.IFCPending) AS SumOfIFCPending, Sum(tblCWP_PercentComplete.IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete;"
    intTotals = OpenRecordSet(rsTotals, strsql)


    If intTotals > 0 Then


    dblPercentComplete = ((rsTotals.Fields("SumOfConfirmed") * dblConfirmedPercent) _
    + (rsTotals.Fields("SumOfAssembled") * dblPackageAssembledPercent) _
    + (rsTotals.Fields("SumOfReset") * dblResetPercent) _
    + (rsTotals.Fields("SumOfReDesignRequired") * dblReDesignRequiredPercent) _
    + (rsTotals.Fields("SumOfDesignComplete") * dblDesignCompletePercent) _
    + (rsTotals.Fields("SumOf3DCaddComplete") * dbl3DCaddCompletePercent) _
    + (rsTotals.Fields("SumOfReCaddRequired") * dblReCaddRequiredPercent) _
    + (rsTotals.Fields("SumOf2DCaddComplete") * dbl2DCaddCompletePercent) _
    + (rsTotals.Fields("SumOfQCReviewComplete") * dblQCReviewCompletePercent) _
    + (rsTotals.Fields("SumOfCheckingComplete") * dblCheckingCompletePercent) _
    + (rsTotals.Fields("SumOfIFCPending") * dblIFCPendingPercent) _
    + (rsTotals.Fields("SumOfIFC") * dblIFCPercent)) _
    / CInt(rsTotals.Fields("SumOfTotal"))
    Else
    dblPercentComplete = 0
    End If
    strsql = "INSERT INTO tblCWP_PercentComplete (EHT_EWP, Total, Confirmed, Assembled, Reset, ReDesignRequired, DesignComplete, 3DCaddComplete, " & _
    "ReCaddRequired, 2DCaddComplete, QCReviewComplete, CheckingComplete, IFCPending, IFC, PercentComplete) " & _
    "SELECT 'TOTAL', " & rsTotals.Fields("SumOfTotal") & ", " & _
    rsTotals.Fields("SumOfConfirmed") & ", " & rsTotals.Fields("SumOfAssembled") & ", " & _
    rsTotals.Fields("SumOfReset") & ", " & rsTotals.Fields("SumOfReDesignRequired") & ", " & _
    rsTotals.Fields("SumOfDesignComplete") & ", " & rsTotals.Fields("SumOf3DCaddComplete") & ", " & _
    rsTotals.Fields("SumOfReCaddRequired") & ", " & rsTotals.Fields("SumOf2DCaddComplete") & ", " & _
    rsTotals.Fields("SumOfQCReviewComplete") & ", " & rsTotals.Fields("SumOfCheckingComplete") & ", " & _
    rsTotals.Fields("SumOfIFCPending") & ", " & _
    rsTotals.Fields("SumOfIFC") & ", " & Format(dblPercentComplete, "0.00") & ";"
    CurrentDb.Execute strsql

    DoCmd.OpenTable "tblCWP_PercentComplete"


    End Sub

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you have names starting with a number which is probably the reason - see this link for the rationale and discussion http://stackoverflow.com/questions/1...t-with-numeric

    It may be solvable by using square brackets around the name, but better to change the name

  3. #3
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    109
    Ajax
    Thanks for your help, the number was also my "suspect" but with my limited knowledge of vba I wasn't sure. Looks like renaming the fields is the right solution as you suggest.
    HS_1

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    it's not so much vba (tho' not advisable there either) as sql - you are just using vba to create a sql statement

  5. #5
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    109

    New error message

    Quote Originally Posted by Ajax View Post
    it's not so much vba (tho' not advisable there either) as sql - you are just using vba to create a sql statement
    Ajax sorry for bothering you again. I have renamed the fields as you suggested but new error message appeared.

    The SELECT statement includes a reserved word or an argument

    Name that is misspelled or misusing, or the punctuation isincorrect.

    I am looking at it for hours but can't find a mistake, do you think the "Total" would be the problem?
    Thanks




    ' Add Totals line at the bottom
    strsql = "SELECT Sum(tblCWP_PercentComplete.Total) AS SumOfTotal, Sum(tblCWP_PercentComplete.Assembled) AS SumOfAssembled, " & _
    "Sum(tblCWP_PercentComplete.Reset) AS SumOfReset, Sum(tblCWP_PercentComplete.ReDesignRequired) AS SumOfReDesignRequired, " & _
    "Sum(tblCWP_PercentComplete.DesignComplete) AS SumOfDesignComplete, Sum(tblCWP_PercentComplete.Cadd3DComplete) AS SumOfCadd3DComplete " & _
    "Sum(tblCWP_PercentComplete.ReCaddRequired) AS SumOfReCaddRequired, Sum(tblCWP_PercentComplete.Cadd2DComplete) AS SumOfCadd2DComplete " & _
    "Sum(tblCWP_PercentComplete.QCReviewComplete) AS SumOfQCReviewComplete, Sum(tblCWP_PercentComplete.CheckingComplete) AS SumOfCheckingComplete " & _
    "Sum(tblCWP_PercentComplete.IFCPending) AS SumOfIFCPending, Sum(tblCWP_PercentComplete.IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete;"
    intTotals = OpenRecordSet(rsTotals, strsql)
    If intTotals > 0 Then
    dblPercentComplete = ((rsTotals.Fields("SumOfConfirmed") * dblConfirmedPercent) _
    + (rsTotals.Fields("SumOfAssembled") * dblPackageAssembledPercent) _
    + (rsTotals.Fields("SumOfReset") * dblResetPercent) _
    + (rsTotals.Fields("SumOfReDesignRequired") * dblReDesignRequiredPercent) _
    + (rsTotals.Fields("SumOfDesignComplete") * dblDesignCompletePercent) _
    + (rsTotals.Fields("SumOfCadd3DComplete") * dblCadd3DCompletePercent) _
    + (rsTotals.Fields("SumOfReCaddRequired") * dblReCaddRequiredPercent) _
    + (rsTotals.Fields("SumOfCadd2DComplete") * dblCadd2DCompletePercent) _
    + (rsTotals.Fields("SumOfQCReviewComplete") * dblQCReviewCompletePercent) _
    + (rsTotals.Fields("SumOfCheckingComplete") * dblCheckingCompletePercent) _
    + (rsTotals.Fields("SumOfIFCPending") * dblIFCPendingPercent) _
    + (rsTotals.Fields("SumOfIFC") * dblIFCPercent)) _
    / CInt(rsTotals.Fields("SumOfTotal"))
    Else
    dblPercentComplete = 0
    End If
    strsql = "INSERT INTO tblCWP_PercentComplete (EHT_EWP, Total, Confirmed, Assembled, Reset, ReDesignRequired, DesignComplete, Cadd3DComplete, " & _
    "ReCaddRequired, Cadd2DComplete, QCReviewComplete, CheckingComplete, IFCPending, IFC, PercentComplete) " & _
    "SELECT 'TOTAL', " & rsTotals.Fields("SumOfTotal") & ", " & _
    rsTotals.Fields("SumOfConfirmed") & ", " & rsTotals.Fields("SumOfAssembled") & ", " & _
    rsTotals.Fields("SumOfReset") & ", " & rsTotals.Fields("SumOfReDesignRequired") & ", " & _
    rsTotals.Fields("SumOfDesignComplete") & ", " & rsTotals.Fields("SumOfCadd3DComplete") & ", " & _
    rsTotals.Fields("SumOfReCaddRequired") & ", " & rsTotals.Fields("SumOfCadd2DComplete") & ", " & _
    rsTotals.Fields("SumOfQCReviewComplete") & ", " & rsTotals.Fields("SumOfCheckingComplete") & ", " & _
    rsTotals.Fields("SumOfIFCPending") & ", " & _
    rsTotals.Fields("SumOfIFC") & ", " & Format(dblPercentComplete, "0.00") & ";"
    CurrentDb.Execute strsql

    DoCmd.OpenTable "tblCWP_PercentComplete"
    End Sub

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quick look finds 3 missing commas causing syntax errors:

    Code:
    strsql = "SELECT Sum(tblCWP_PercentComplete.Total) AS SumOfTotal, Sum(tblCWP_PercentComplete.Assembled) AS SumOfAssembled, " & _
    "Sum(tblCWP_PercentComplete.Reset) AS SumOfReset, Sum(tblCWP_PercentComplete.ReDesignRequired) AS SumOfReDesignRequired, " & _
    "Sum(tblCWP_PercentComplete.DesignComplete) AS SumOfDesignComplete, Sum(tblCWP_PercentComplete.Cadd3DComplete) AS SumOfCadd3DComplete, " & _
    "Sum(tblCWP_PercentComplete.ReCaddRequired) AS SumOfReCaddRequired, Sum(tblCWP_PercentComplete.Cadd2DComplete) AS SumOfCadd2DComplete, " & _
    "Sum(tblCWP_PercentComplete.QCReviewComplete) AS SumOfQCReviewComplete, Sum(tblCWP_PercentComplete.CheckingComplete) AS SumOfCheckingComplete, " & _
    "Sum(tblCWP_PercentComplete.IFCPending) AS SumOfIFCPending, Sum(tblCWP_PercentComplete.IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete;"

  7. #7
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    109
    Thanks davegri, and Ajax without your help I wouldn't be able to figure this out, finally it works as it suppose to
    HS_1

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    some tips for the future to make you code more readable, shorter and quicker

    1. in vba coding use indents - and when presenting to others to help, preserve that indenting by surrounding the posted code with the code tags (the # button)
    2. in sql don't use such long names for tables - and if you have to, alias them - as an example this

    Code:
    ...
    ...
    "Sum(tblCWP_PercentComplete.IFCPending) AS SumOfIFCPending, Sum(tblCWP_PercentComplete.IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete;"
    is reduced to
    Code:
    ...
    ...
    "Sum(PC.IFCPending) AS SumOfIFCPending, Sum(PC.IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete PC;"
    and in fact, on this occasion since there is only one table (or more precisely, there is no question over where a field name comes from) you don't need to identify the table

    Code:
    ...
    ...
    "Sum(IFCPending) AS SumOfIFCPending, Sum(IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete;"
    3. use With so you don't have to keep referring to the object

    so this
    Code:
    rsTotals.Fields("SumOfConfirmed") & ", " & rsTotals.Fields("SumOfAssembled") & ", " & _
    rsTotals.Fields("SumOfReset") & ", " & rsTotals.Fields("SumOfReDesignRequired") & ", " & _
    becomes

    Code:
    with rsTotals
       !SumOfConfirmed & ", " & !SumOfAssembled & ", " & _
       !SumOfReset & ", " & !SumOfReDesignRequired & ", " & _
       ...
       ...
    end with

  9. #9
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    109

    Ajax thanks for the tips

    Ajax thanks for the helpful tips, I really appreciate your help and advice.
    HS_1



    Quote Originally Posted by Ajax View Post
    some tips for the future to make you code more readable, shorter and quicker

    1. in vba coding use indents - and when presenting to others to help, preserve that indenting by surrounding the posted code with the code tags (the # button)
    2. in sql don't use such long names for tables - and if you have to, alias them - as an example this

    Code:
    ...
    ...
    "Sum(tblCWP_PercentComplete.IFCPending) AS SumOfIFCPending, Sum(tblCWP_PercentComplete.IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete;"
    is reduced to
    Code:
    ...
    ...
    "Sum(PC.IFCPending) AS SumOfIFCPending, Sum(PC.IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete PC;"
    and in fact, on this occasion since there is only one table (or more precisely, there is no question over where a field name comes from) you don't need to identify the table

    Code:
    ...
    ...
    "Sum(IFCPending) AS SumOfIFCPending, Sum(IFC) AS SumOfIFC " & _
    "FROM tblCWP_PercentComplete;"
    3. use With so you don't have to keep referring to the object

    so this
    Code:
    rsTotals.Fields("SumOfConfirmed") & ", " & rsTotals.Fields("SumOfAssembled") & ", " & _
    rsTotals.Fields("SumOfReset") & ", " & rsTotals.Fields("SumOfReDesignRequired") & ", " & _
    becomes

    Code:
    with rsTotals
       !SumOfConfirmed & ", " & !SumOfAssembled & ", " & _
       !SumOfReset & ", " & !SumOfReDesignRequired & ", " & _
       ...
       ...
    end with

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

Similar Threads

  1. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  2. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  3. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  4. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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