Unable to execute stored query!

  • OzGrid / Et Al,


    I think I'm just being dense here.


    I have a table that:


    Name: tbl_Coat_ResistCost
    Field1: ResistCost ( Text, 50 )
    Field2: CostPerLiter ( Number, Double, 2 )


    I have an INSERT query of: ( it works when ran from Access )
    INSERT INTO tbl_Coat_ResistCost ( CostPerLiter, ResistType )
    VALUES ([Tgt ResistCost], [Tgt ResistID]);


    Now in excel I've got this routine which wants to use the above query to add new values.


    The error that I get is in the attached file.
    "Data Type Mismatch"


    Now I've been trying to change the "adDouble" because I'm 99% certain it's not the "adVarChar". Yes, the calling routine verifyes the appropriate values of the first two incomming values.


    The "blnAddResist" value is "TRUE" at run time.


    The routine which creates the connection follows. I've highlighted the section that creates the connection object in this instance.

  • Re: Unable to execute stored query!


    Not sure (as I have not done it this way before), but what about when you specify the parameters you use the []? For example

    Code
    adoCmd.Parameters("[Tgt ResistID]") = Trim(strResistID)


    A.

  • Re: Unable to execute stored query!


    A,


    Not sure how that would work. And now not being at work won't be able to try it. Though I've never had to do that before. It seem to me as if the I was indicating the wrong type of field value.



    The "[]" in the queries indicate to Access that there is supposed to be a entered value. That way you're queries are dynamic and not static.



    Will look into this next week at work.

  • Re: Unable to execute stored query!


    Bump!


    Anyone...Anyone :)

  • Re: Unable to execute stored query!


    iwrk4dedpr


    try to adapt this code ( I did from db to db just to check it fast - It works for me! )



    regards


    Filippo

  • Re: Unable to execute stored query!


    Filippo,


    Thanks for the suggestion. I'm trying to keep all queries stored in the database. So that way if/when I port to a more robust database ( SQL most likely ) that I can use stored queries. So I want to create and keep all queries in it's respective database.



    Though this will be my alternative if I'm not able to determine the cause of the error.

  • Re: Unable to execute stored query!


    could it be that the line

    Code
    adoCmd.Parameters("Tgt ResistID") = Trim(strResistID)


    should be written - being a String -

    Code
    adoCmd.Parameters("Tgt ResistID") = "'" & Trim(strResistID)  &"'"


    ?


    regards


    Filippo

  • Re: Unable to execute stored query!


    Hi Barry,


    Not sure, but have you tried swaaping around your parameters


    i.e.


    Code
    Set adoPrm = adoCmd.CreateParameter("Tgt ResistCost", adDouble, adParamInput, 2) 
        adoCmd.Parameters.Append adoPrm 
        adoCmd.Parameters("Tgt ResistCost") = CDbl(strResistCost)
    Set adoPrm = adoCmd.CreateParameter("Tgt ResistID", adVarChar, adParamInput, 50) 
        adoCmd.Parameters.Append adoPrm 
        adoCmd.Parameters("Tgt ResistID") = Trim(strResistID)


    as opposed to this


    Code
    Set adoPrm = adoCmd.CreateParameter("Tgt ResistID", adVarChar, adParamInput, 50) 
        adoCmd.Parameters.Append adoPrm 
        adoCmd.Parameters("Tgt ResistID") = Trim(strResistID) 
        Set adoPrm = adoCmd.CreateParameter("Tgt ResistCost", adDouble, adParamInput, 2) 
        adoCmd.Parameters.Append adoPrm 
        adoCmd.Parameters("Tgt ResistCost") = CDbl(strResistCost)


    As I notice that's the order in your Access Query...

  • Re: Unable to execute stored query!


    OzGrid / Et Al, ( Flippo / Will / Shark )


    I usually have so much integration with most of my projects that tearing out the problem areas is usually not an option. But . . .



    Attached find 2 .zip files. In one is a workbook which has a form ( there's no macro to show it so it needs to be ran from the IDE ). It also has a text file that is export of the table from the database ( had to take the table out to get the file small enough to attach )


    The other is the database ( minus the table of data )



    1. Extract all files
    2. Import the .txt file into a table called
    _ tbl_Coat_ResistCost
    3. Change the folder references in the routine on the form to point to the database where you put it.
    4. Show the form
    5. Middle tab
    6. Lower Left Corner ( trying to update the cost of a selected resist )



    I'm also going to post a thread at UtterAccess as well and point back to this thread. God willing someone will slap the light into my head! :confused:



    Oh, and this is important too.
    I've monkeyed around with stuff so much now that the original error isn't comming up. Now when this runs ( when trying to update a cost ) it executes all the way through ( with no errors ) but it doesn't actually change the cost in the table. Sorry to change the game plan on ya'll.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!