Results 1 to 27 of 27

Thread: [RESOLVED] ERROR: Application uses a value of the wrong type for the current operation

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [RESOLVED] ERROR: Application uses a value of the wrong type for the current operation

    I am using the example from the FAQ's titled - How Can I Add A Record To A Database, but I am trying to update a record, not add it.

    I have the following code but get the error:
    Application uses a value of the wrong type for the current operation
    on the line that starts .Parameters.Append .......

    Now, I'm not to sure what this exactly means, but is it something to do with the 4th parameter of the code to add - '50'?
    What does this '50' stand for?
    Is it the length of the string added?

    vb Code:
    1. strSQL = "UPDATE INTO tbl_Code (Code_Text) VALUES (rtfcode.text)"
    2.  
    3. With adoCmd
    4.     .ActiveConnection = cn
    5.     .CommandType = adCmdText
    6.     .CommandText = strSQL
    7.     .Prepared = True
    8.     .Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, rtfCode.Text)
    9.     .Execute , , adCmdText + adExecuteNoRecords
    10. End With
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ERROR: Application uses a value of the wrong type for the current operation

    It is not UPDATE INTO

    It is simply UPDATE tablename SET fieldname = '" & Text1.Text & "' "

    INTO is used with INSERT

    Also, there is no VALUES clause with an UPDATE

    Again, that is only used with INSERT

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Also, as you are using a Command you should not put any values into the SQL statement - just ? as a placeholder, eg:

    "UPDATE tablename SET fieldname = ? "

    These are then filled from the parameters that you append.

    Now, I'm not to sure what this exactly means, but is it something to do with the 4th parameter of the code to add - '50'?
    What does this '50' stand for?
    Is it the length of the string added?
    It's easy to find out.. click on CreateParameter and press F1.

  4. #4

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Thanks Hack and si_the_geek

    I have changed the SQL completely as you both suggested, but I still have the error.
    I will take a look on MSDN online

    Quote Originally Posted by si_the_geek
    It's easy to find out.. click on CreateParameter and press F1
    Um, I can't. I installed MSDN but the link between VB6 and MSDN doesn't seem to work.
    It may be some sort of registry entry, but if it is, I wouldn't have a clue where to start looking.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Is that MSDN in general (in which case I'd recommend re-installing it), or does it work for other things like With?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ERROR: Application uses a value of the wrong type for the current operation

    What does your code look like now?

  7. #7

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Quote Originally Posted by si_the_geek
    Is that MSDN in general (in which case I'd recommend re-installing it), or does it work for other things like With?
    Error message says MSDN not installed for anything.
    I have re-installed it twice now, once straight after re-installing VB6

    Quote Originally Posted by Hack
    What does your code look like now?
    vb Code:
    1. strSQL = "UPDATE tbl_Code SET Code_Text = ?"
    2.  
    3. With adoCmd
    4.     .ActiveConnection = cn
    5.     .CommandType = adCmdText
    6.     .CommandText = strSQL
    7.     .Prepared = True
    8.     .Parameters.Append .CreateParameter(, adVarChar, adParamInput, 3000, rtfCode.Text)
    9.     .Execute , , adCmdText + adExecuteNoRecords
    10. End With
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ERROR: Application uses a value of the wrong type for the current operation

    In that case I'd recommend looking at previous threads about the MSDN library - I haven't had that kind of issue myself (a re-install has fixed it for me), but I'm pretty sure others have solved it.

    The number is the maximum size of the data, I guess 3000 will be fine.

    I think you should change adVarChar to adLongVarChar, but I'm not completely sure.


    By the way, you should add a Where clause to the Update (eg: "WHERE CodeID = ?"), otherwise it will update all rows in the table!

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Reinstall MSDN, but DO NOT do a "Typical" install.

    Instead, run a FULL install.

  10. #10

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Quote Originally Posted by Hack
    Reinstall MSDN, but DO NOT do a "Typical" install.

    Instead, run a FULL install.
    I have a day off tomorrow, I will give this a go then, thanks.

    I now have this code, but still with the same error:
    vb Code:
    1. strSQL = "UPDATE tbl_Code WHERE Code_Description = '" & CategoryToLoad & "' SET Code_Text = ?"
    2.  
    3. With adoCmd
    4.     .ActiveConnection = cn
    5.     .CommandType = adCmdText
    6.     .CommandText = strSQL
    7.     .Prepared = True
    8.     .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, 3000, rtfCode.Text)
    9.     .Execute , , adCmdText + adExecuteNoRecords
    10. End With

    The error says that the "rtfCode.Text" value is the wrong type. It says in MSDN that it is a Variant. Why would this cause a problem?
    Quote Originally Posted by MSDN
    Visual Basic Reference. Variant data type. A special data type that can contain numeric, string, or date data as well as user-defined types and the special values ...
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Try setting rtfCode.Text to a string variable first, check that it's correct, then use that in the code.
    I'm not sure the code recognizes what rtfCode is. Usually you have to refer to the form in some way to access the controls - Me.rtfCode, for example. However, I'm used to working with Access/DAO, so may be wrong here.
    Tengo mas preguntas que contestas

  12. #12

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Quote Originally Posted by salvelinus
    Try setting rtfCode.Text to a string variable first, check that it's correct, then use that in the code.
    Thanks salvelinus,
    I have already tried this and it still had the same error.
    I haven't tried "Me.rtfCode.Text" so I will give that a go.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Your query should read:
    Code:
    strSQL = "UPDATE tbl_Code SET Code_Text = ? "
    strSQL = strSQL & "WHERE Code_Description = '" & CategoryToLoad & "' "

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Actually it should be like this:
    Code:
    strSQL = "UPDATE tbl_Code SET Code_Text = ? WHERE Code_Description = ?"
    ..with another parameter for Code_Description.

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Good point.

  16. #16

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Quote Originally Posted by si_the_geek
    ..with another parameter for Code_Description.
    So for every '?' you add, it adds a parameter to the CreateParameter?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Something like that... each ? is a potential parameter.

    You need to use CreateParameter etc to 'convert' it into one, and put a value into it.

  18. #18

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    I think I have got that with the following.
    It goes past the first Parameter, but still errors out on the second.

    CategoryToLoad returns the Code_Description as expected.

    vb Code:
    1. strSQL = "UPDATE tbl_Code SET Code_Text = ?"
    2. strSQL = strSQL & " WHERE Code_Description = ?"
    3.  
    4. With adoCmd
    5.     .ActiveConnection = cn
    6.     .CommandType = adCmdText
    7.     .CommandText = strSQL
    8.     .Prepared = True
    9.     .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, 50, CategoryToLoad)
    10.     .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, 3000, rtfCode.Text)
    11.     .Execute , , adCmdText + adExecuteNoRecords
    12. End With
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  19. #19
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ERROR: Application uses a value of the wrong type for the current operation

    You need to change the order of the parameters, so that they are created in the same order that they appear in the SQL statement.

    There isn't anything obviously wrong with your code... as I'm short on time I can only suggest you try using a different data type, such as adChar / adLongVarWChar / adVarWChar / adWChar

  20. #20
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: ERROR: Application uses a value of the wrong type for the current operation

    What is the length of the text in the rtfCode control?
    That error occurs when the Value's length is greater than the size argument.

    .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, Len(rtfCode.Text), rtfCode.Text)

    Also, since you are executing a sql statement the Parameter's data type is almost irrelevant, as long as the Value matches the Type (or the Value can be implicity converted to the Type) it should work.

  21. #21

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Thanks si and bruce.

    This change now stops the original error;
    Code:
    .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, Len(rtfCode.Text) ,rtfCode.Text)
    but doesn't save the changes!

    If I change the order of the parameters to this, it now gives me the error;
    The Search key was not found in any record
    on the Execute line;
    vb Code:
    1. .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, Len(rtfCode.Text), rtfCode.Text)
    2. .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, Len(CategoryToLoad), CategoryToLoad)
    3. .Execute , , adCmdText + adExecuteNoRecords
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  22. #22

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    I have got a bit further along with this one.

    I now have worked through this and found that this code WILL save files that aren't too big. The larger files error out on the Execute line with this error:
    Run-Time Error '-2147467259(80004005)
    The search key was not found in any record


    What exactly does this mean? I have done a lot of searching and it seems to have various answers.

    Anyway, I now know it works with smaller text (string) entries, so this may give somebody an idea what is causing this.

    vb Code:
    1. strSQL = "UPDATE tbl_Code SET Code_Text = ?"
    2. strSQL = strSQL & " WHERE Code_Description = ?"
    3.  
    4. With adoCmd
    5.     .ActiveConnection = cn
    6.     .CommandType = adCmdText
    7.     .CommandText = strSQL
    8.     .Prepared = True
    9.     .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, Len(rtfCode.Text), rtfCode.Text)
    10.     .Parameters.Append .CreateParameter(, adLongVarChar, adParamInput, Len(CategoryToLoad), CategoryToLoad)
    11.     .Execute , , adCmdText + adExecuteNoRecords
    12. End With
    13.  
    14. cn.Close
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  23. #23

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Quote Originally Posted by si_the_geek
    There isn't anything obviously wrong with your code...
    as I'm short on time I can only suggest you try using a different data type, such as adChar / adLongVarWChar / adVarWChar / adWChar
    I tried all of these and they all give the same error as in the last post
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  24. #24
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ERROR: Application uses a value of the wrong type for the current operation

    From post #22 I assume it is purely down to the length. What size is the amount of characters that are "safe", and "fail"?

    The size of a memo is "up to 64,000 characters.", so that in itself is probably not the issue - I suspect that you are reaching the limit of another part of the process .

  25. #25

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    The length of CategoryToLoad is no more than 100 characters, set in the DB design View.

    The length of rtfCode.text varies.

    Original length for testing = 2234

    3198 chars fails
    1334 passes

    Tested some more:
    2234 passes
    2316 fails

    tested more again:

    2199 failed
    2233 failed
    2234 > 1546 failed
    Last edited by aikidokid; Apr 16th, 2007 at 01:41 PM.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  26. #26
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: ERROR: Application uses a value of the wrong type for the current operation

    How big is your database? Can you zip it and post it here?

    This is an unusual error and I don't believe it has anything to do with your code. A quick search on google indicates it might be a corrupt database issue. Try a compact and repair.

    Another possible cause is that the memo field has an index. Remove it if that is the case.

    http://forums.aspfree.com/microsoft-...ord-18419.html

  27. #27

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: ERROR: Application uses a value of the wrong type for the current operation

    Quote Originally Posted by brucevde
    This is an unusual error and I don't believe it has anything to do with your code. A quick search on google indicates it might be a corrupt database issue. Try a compact and repair.
    I did this first and it seemed to work and then fail, and generally be inconsistant.

    Quote Originally Posted by brucevde
    Another possible cause is that the memo field has an index. Remove it if that is the case.
    I have two memo fields, one of which had an index. I have removed this now, and hopefully, so far all is well.
    I will test it a bit more, but so far large or small files can be saved.

    Thanks for the link - very helpful and interesting.

    I came across one site in my travels that had so many different reasons for the one error I didn't know where to begin.
    This thread was exactly what I was experiencing.
    Bookmarked this site now

    Thanks for the help brucevbd.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

Posting Permissions

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



Click Here to Expand Forum to Full Width