Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2012
    Posts
    7

    Unanswered: What's wrong here?

    Inexperienced "programmer": I get a "too few parameters" error when I put the " * Factor" in my As TestingCost statement. Factor is dim as double.

    If UnitType = "AC" Or UnitType = "CC" Then
    Factor = 0.5
    ElseIf UnitType = "CT" Or UnitType = "TB" Then
    Factor = 1
    ElseIf UnitType = "DS" Then
    Factor = 2
    ElseIf UnitType = "PAD" Or UnitType = "SCB" Then
    Factor = 0
    End If

    SQL = "INSERT INTO tempCatalogValue ( CATCatalogID, AggregateValue ) " _
    & "SELECT Catalog.CATCatalogID, " _
    & "[testcostrate] * nz([CabinetSizingFactor],0) * Factor " _
    & "AS TestingCost " _
    & "FROM [Fixed Values], [Catalog] " _
    & "INNER JOIN [Cabinet Time] ON Catalog.CATCabinet = [Cabinet Time].Cabinet;"

    CurrentDb.Execute SQL

    Thanks for your help.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what happens when you examine the variable SQL
    either display it in a msgbox or put the mouse over SQL in the code and see what its saying

    to few parameters usually means that there is a screw up int he amount of data presented to a function

    in this case although you have code which compiles (seems OK) in VB its not valid SQL.

    its do with how you have built up the SQL.
    when you want to inlcude values from forms, controls or elsewhere you need to be 'outside' the quote
    eg
    strSQl = "select my, column, list from mytable"
    strSQl = strsql & " where acolumn = 1"
    strSQl = strsql & " and anothercolumn = " & anumericvariable"
    strSQl = strsql & " and yetanothercolumn = '" & astringvariable & "'"


    just a comment on your IF statement, what happens if the unit type ins't one of your expected values, what default value do you have for factor?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2012
    Posts
    7

    Actually it is good SQL because it works, just...

    Not with the Factor in. If I replace the AS TestingCost statement with:

    & "[testcostrate] * nz([CabinetSizingFactor],0) " _
    & "AS TestingCost " _

    It works.

    Don't I need some combination of & and Factor and " and ' ? I can never figure that out?

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what does that tell you
    what happens if you have a user type that isn't
    "AC", "CC", "CT", "TB" or "DS"?

    my guess is that you have not declared what type of data factor is (ie its not been explicitly declared and you are not using 'option explicit'

    I suspect that you need to add option explict to all code modules, and also to the preferences in your access environment if available
    then declare factor, eg:-
    dim Factor as single
    then set a default value before the if or better yet as a final 'else'
    Code:
    If UnitType = "AC" Or UnitType = "CC" Then
      Factor = 0.5
    ElseIf UnitType = "CT" Or UnitType = "TB" Then
      Factor = 1
    ElseIf UnitType = "DS" Then
      Factor = 2
    ElseIf UnitType = "PAD" Or UnitType = "SCB" Then
      Factor = 0
    else
      Factor = 1
    End If
    or 0 or whatever value is relevant
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2012
    Posts
    7

    I agree

    I need Else Factor = 1 but I still get the same problem.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'd run the sub select statement and seek to prove that it can generate the values you require

    you may need the values predicate as part of the insert into
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    I would use the select case easier to read

    Select unittype

    Case "AC","CC"
    Factor = 0.5
    Case "CT","TB"
    Factor = 1
    Case else
    Factor = 1
    End select
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •