Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-04
4
Medium Priority
?
395 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 51

Accepted Solution

by:
Steve Bink earned 248 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 248 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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