Solved

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

Posted on 2004-04-04
4
360 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
Comment Utility
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
Comment Utility
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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.

744 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

18 Experts available now in Live!

Get 1:1 Help Now