Solved

Run-time error '3421': Data type conversion error.  HELP!!!

Posted on 2004-04-04
4
367 Views
Last Modified: 2008-02-01
Okay, the short version of the problem is this:  I've got a fairly simple data entry form which I created using the creat form wizard and then customized on my own.  It has a query passed to it from another form upon loading, and it appropriately shows the correct number of records for the query.  I should then be able to either update or add any record from then on.  However, whenever I try either to change any field of an existing record or add a new record, I always get the following error:

Run-time error '3421':
Data type conversion error.

Here is a copy of all of the code behind the form:

<b>
Option Compare Database

Private msReportName As String

Private Sub btnExit_Click()
    DoCmd.Close
End Sub

Private Sub cmdBack_Click()
    Form_wizUpdateTemplate.Move Me.WindowLeft, Me.WindowTop
    Form_wizUpdateTemplate.Visible = True
    Me.Visible = False
End Sub

Public Property Get MyReportName() As String
    MyReportName = msReportName
End Property

Public Property Let MyReportName(asVal As String)
    msReportName = asVal
End Property

Private Sub Form_BeforeUpdate(Cancel As Integer)
<i>    Form.Recordset.Update "ReportName", MyReportName</i>
End Sub
</b>

The italicized line is where it dies at.

Here is something very important that I should mention: While this is ultimately a very simple data entry/edit form, there is one field for each row which I do *NOT* want the user to have to edit or even be able to see.  This field contains the primary key which must be the same for each row in the dataset in the form.  If this field is left blank, the program will not be able to retrieve the newly added row for each subsequent query.  Unfortunately, the default is for this field to be left blank, and having it auto-populate by setting the "default value" in the table is insufficent because this value will change depending on the query which is passed to the form.

Anyway, I just thought I'd mention the above in case you were wondering why I didn't just leave it at what the wizard created.

Any ideas on how to fix this error?

I really appreciate the help!
0
Comment
Question by:sanchoz28
4 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 62 total points
ID: 10752643
The Recordset.Update method definition is this:

 Update([UpdateType As Long = 1], [Force As Boolean = False])

The UpdateType should be number, indicating a regular update, a batch update, or current record update.  The Force argument tells Access whether or not to persist your change if the underlying data has already been changed since you opened the recordset.

When you use this line of code:

Form.Recordset.Update "ReportName", MyReportName

"ReportName" is a string, and cannot be converted to type Long.  MyReportName is also a string (as per the Property declaration), and I am unsure how Access will translate that as Boolean...most likely, you'll get the same error with that one.  The OnBeforeUpdate event for the form will trigger after you have changed data in a record and just before the form tries to actually update the underlying table or query, which is why the error only occurs after you change data and try to save it (by moving to another/new record, or a save function).  What are you trying to do with that line of code?  My opinion is that you are using the wrong method for what you want, and possibly the wrong event as well.

For your key value field, set a text box on the form as bound to your key field.  You can keep your users out of it by setting the Visible property to False.  If you do not mind the users seeing the field, but want to make sure they cannot edit it, set the Locked property to True, or the Enabled property to False.
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 62 total points
ID: 10752649
not sure if you are affected by this

http://dbforums.com/arch/42/2002/8/448717

regarding yuour primary key field, you can set the properties of the field to visible = False, that should hide it
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now