-
Nov 27th, 2022, 05:19 AM
#1
Thread Starter
Addicted Member
VB6 To Add a record I get Type mismatch error 2147352571
VB6, Database access I am using DAODB it's an Index table and does not accept duplicates, I get (Type mismatch error 2147352571) I would like to bypass the index but, I do not know how can I do it. The first field sends me that error. Somebody can help me please to solve this issue. Thank you in advance
Private Sub Command2_Click()
rs.AddNew
rs.Fields(0).Value = Text1.Text
rs.Fields(1).Value = Text2.Text
rs.Fields(2).Value = Text3.Text
rs.Fields(3).Value = Text4.Text
rs.Fields(4).Value = Text5.Text
rs.Update
-
Nov 27th, 2022, 09:36 AM
#2
Re: VB6 To Add a record I get Type mismatch error 2147352571
Just looking at it, my first thoughts are:
Is the RecordSet actually open, and open in a way that allows adding new records?
What is the actual type of the first field in your recordset? Easiest way to check that is to open the database in MS-Access and see what it is. If it's not text (or memo), that might be your problem. Or, is the field too small? to hold Text1.Text?
Just some ideas.
And just an FYI, I use the DAO extensively. However, I virtually never use it with indexed (numeric) Fields values, as IMHO that's just asking for trouble. You can also use named fields:
rs.Fields("MyFieldName").Value = Text1.Text
That way, if you insert another field into your database, everything still goes to the correct place even if the new field isn't populated.
EDIT: Just re-read your post. If you've got an indexed (no dupes) field in your database, just open the database with MS-Access, open that table for design, open your indexes, and delete whatever index you want. Then, you'll have no problem with indexes.
You can do that with VB6 code, but it's easiest to just do it from MS-Access.
Last edited by Elroy; Nov 27th, 2022 at 09:39 AM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Nov 28th, 2022, 08:01 PM
#3
Re: VB6 To Add a record I get Type mismatch error 2147352571
Type mismatch means there is an issue with the data you are trying to put into one or more fields. .Text is a string if you try to put a string into a numeric or date field you can get a type mismatch. Check you data types in your db and make sure when you update the record you use the correct data type. VB of course will often allow you to treat a string as a number but a string may not contain a valid number and in such a case it is not possible to treat it as a number. As a general rule you should never count on VB to handle strings as numbers or dates, you should use the proper variable types and do any required checks and conversions before you try to update your records.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|