Solved

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

Posted on 2004-04-04
4
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

738 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