Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Conversion Type Failure


Message #1 by "Laur Epstein" <lauran@z...> on Wed, 19 Feb 2003 21:29:24
Hi, Folks,

I would be grateful if anywone can tell what I am doing wrong here.  I am 
inserting records into a SQL Server 7.0 database via Access95.  I have 
changed a value that is being passed and now get the following errors:
~~~~~~~~~~~~~~
Microsoft Access can't append all the records in the Append Query.  
Microsoft set 1 field(s) to Null due to a type conversion failure, and it 
didn't add 0 record(s) to the table due to key violations, 0 record(s) due 
to lock violations, 0 record(s) due to validation rule violations.

Runtime error '2501'.  The RunSQL action was cancelled.



The insert statement goes like this:
~~~~~~~~~~~~~~
For x = Val(Me.StartAt) To Val(Me.StartAt) + Val(Me.TotalImages) - 1
DoCmd.RunSQL "INSERT into Images_File (Image_ID, Image_Size, Image_Path, 
Status_Id, Status_ref, chg_date) values (" & Val(txtDummy) & ",'CARD','" & 
Trim(Me.Prefix) & "_" & x & "_CARD.JPG'," & "28,0,'" & Date & "')"
Next


I changed the value assigned to txtDummy (Dimmed as String) from:
~~~~~~~~~~~~
txtDummy = RecAdded("Select vewImageMAX_SQ.* from 
vewImageMAX_SQ", "txtadded")

To:
~~~~~~~~~~~~
txtDummy = RecAdded("SELECT MAX(image_counter)AS lastcounter FROM images 
WHERE Image_Number = " & Me.ID & " AND Image_Level = '" & Left
(Me.txtLevel, 1) & "'", "LastCounter"))

These call a homegrown function, RecAdded:
~~~~~~~~~~~~~~~~~~~~
Public Function RecAdded(strtabel As String, strId As String)
    Dim strX
    If Len(strtabel) > 6 Then
       Dim dbs As Database, rst As Recordset
       Set dbs = CurrentDb
       Set rst = dbs.OpenRecordset(strtabel, dbOpenDynaset, dbSeeChanges, 
dbReadOnly)
       'OpenRecordsetOutput rst
       'MsgBox rst.RecordCount
       'strX = "rst!" & strId
       RecAdded = rst(0)
       rst.Close
       Set dbs = Nothing
    End If
End Function
~~~~~~~~~~~~~~~~~~~

When I check the results with a message box, each version of txtDummy 
gives me a value, but somehow the value on the newer version cannot be 
used in my insert statement.  Any thoughts on what is wrong or how I can 
determine the datatype of the new value?  I did try converting the result 
with a Str() funtion but it doesn't help.

With many thanks for your insights,
Lauran
Message #2 by "Laur Epstein" <lauran@z...> on Thu, 20 Feb 2003 17:54:39
I have found another way of doing this.  Many thanks!

  Return to Index