After converted the Access 2003 to 2007, the program does not work

A

A. J.

I had a 2003 version of the Access database which was working well; now I
converted to the 2007 version, it did not read the files as before. Here is
the code section:

Option Compare Database
Option Explicit
Dim SQL As String
Dim FilesTable As New ADODB.Recordset

Public Sub WriteFile(i As Integer, FileName1, CurDir1, RelPath1, a1,
WellID1, PNum1)

FilesTable.AddNew
FilesTable!PNum =PNum1
FilesTable!FileName = FileName1
FilesTable!RelPath = RelPath1
FilesTable!Level = i
….

End Sub

Now when it reads FilesTable.AddNew, it stops reading the following lines of
code and goes back to the calling function to the error message place.

ErrorPath:
If Err.Number = 52 Then
GoTo ExitPath

Could someone give a help? Thanks!
 
T

Tom van Stiphout

On Wed, 21 Oct 2009 12:23:02 -0700, A. J.

That tells me you don't have an error handler in this procedure - go
ahead and add one.
The most likely cause why it failed on that line is that no record
could be added, for example because the recordset is readonly. To test
this, paste the sqlstatement for the recordset into a new query in SQL
view, and switch to design view. Access will point out any syntax
errors. If none, run the query and see if you can add a row. My guess
is you cannot, and you therefore can't expect .AddNew to succeed.

-Tom.
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top