Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

876 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