dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Run Time Error 3421 - Data Type Conversion Error

  1. #1
    Join Date
    Mar 2007
    Posts
    6

    Run Time Error 3421 - Data Type Conversion Error

    I have created a small applet for a local charity and need to add/delete some fields from the access database on the charities site. I want to send a small txt file with the updates to the database, the system already reads a file to see if updates are available. I have used the code from MSDN appenddeletefield but I keep getting the error 3421. I can do the update OK if I hard code the data but that is much more time consumming, and I thought a little file with the data would be better. When running VB6 with the code below the error appears and highlights the line ** .Fields.Append .CreateField((strName), varType, varSize) ** but wont tell me exactly what is wrong. I have attached the code in a txt file JIC. Thanks in advance,
    Tim.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Run Time Error 3421 - Data Type Conversion Error

    Debug.Print the values before you append.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923

    Re: Run Time Error 3421 - Data Type Conversion Error

    Yeah, it is whether varType or varSize that cause the error. Make sure they are valid. Since you use "variant" variable, then it is possible that varType or varSize is considered as a string. You may want to force conversion and also declare those parameters (in your sub) as "long" which will help you find the error.

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  4. #4
    Join Date
    Mar 2007
    Posts
    6

    Re: Run Time Error 3421 - Data Type Conversion Error

    I take it you mean declare it in the 1st line of the sub as per Subname(....varsize as long) I'll give it a go. If irt works many thanks, if not I'll be back, Thansk again, Tim.

  5. #5
    Join Date
    Mar 2007
    Posts
    6

    Exclamation Re: Run Time Error 3421 - Data Type Conversion Error

    I think I've tried what you said Jeff, but it still won't work. I must have my thick head onas I seem to be running around in circles getting nowhere. If you have any furth pointers they would be much appreciated. BTW, I am fairly sure that vartype is a variant and that varsize is a number. I have tried declaring variables of the correct type in Option Explicit dim varsize as long and then filled it from the file and used it directly in the append fields bit & it still gives the same error. Sorry to be a bit thick but I only do this occasionally. Thanks, Tim

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Run Time Error 3421 - Data Type Conversion Error

    Add 3 lines:

    Code:
    	  If strCommand = "APPEND" Then
    		 debug.print varsize
    		 debug.print vartype
    		 stop
    		.Fields.Append .CreateField((strName), varType, varSize)
    	  Else
    		 If strCommand = "DELETE" Then .Fields.Delete strName
    	  End If
       End With
    Then look in the debug window for the values.
    Then, you can change the variables
    varSize=42
    and then press F5 or F8 to single step
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Mar 2007
    Posts
    6

    Re: Run Time Error 3421 - Data Type Conversion Error

    Thanks I'll give that a go.
    Tim

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Run Time Error 3421 - Data Type Conversion Error

    Hope I added that space after append. Just noticed it!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Mar 2007
    Posts
    6

    Re: Run Time Error 3421 - Data Type Conversion Error

    No you didn't, the MSDN code had the space, if I try to remove it VB wants an = somewhere!
    I did what you said & it is the varType that is the problem. It is declared as a variant but as soon as I type in the immediate window varType = dbtext with no quotes the F8 key completes the routine OK. Can you give me a hint on how to get round this ? TIA,
    Tim

  10. #10
    Join Date
    Mar 2007
    Posts
    6

    Re: Run Time Error 3421 - Data Type Conversion Error

    I've got it sorted, it's not pretty but it works. I've set up a select case and if the input variable wtd(d,1)= "dbtext" I then make vartype = dbtext without the quotes. As I say, messy but workable.

    Many thanks both of you for your input, I'll try not to bother you too often, although there are one or two things coming up that will need coding, fingers crossed, Again many thanks, much appreciated,
    Tim

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)