Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2003, 05:15 AM
Authorized User
 
Join Date: Jun 2003
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access 97 Table locking problems

Hi,

I am trying to run some code that adds a new field to a table, does some testng, updates the new field, deletes some records, and deletes the appended field.

The problem I have is when I try to delete the new field at the end I get a "run time 3211 The table is locked". Here is the code:

Dim db As Database
Dim rs As Recordset
Dim tdf As TableDef, fld As Field

Set db = CurrentDb

Set tdf = db.TableDefs("COPY OF TARN")

    With tdf
         'Create new fileds in the recordset and assign field types
        .Fields.Append .CreateField("Delete this record", dbBoolean, 1)
    End With
       ' Append field and refresh collection.
         tdf.Fields.Refresh


Set rs = db.OpenRecordset("COPY OF TARN")
    rs.MoveFirst

    Do Until rs.EOF
       If rs.Fields("Diagnosis1").Value = "MEDICAL CONDITION" Then
          'Test Departure Methd
           If Right(rs.Fields("DepartureMethod").Value, 7) = "MA UNIT" Then
              rs.Edit
              rs.Fields("Delete this record").Value = True
              rs.Update
             Else
               If Right(rs.Fields("DepartureMethod").Value, 8) = "(WARD V)" Then
                  rs.Edit
                  rs.Fields("Delete this record").Value = True
                  rs.Update
               End If
           End If
       End If
    rs.MoveNext
    Loop

  'DoCmd.RunSQL "DELETE [COPY OF TARN].*, [COPY OF TARN].[Delete this record]FROM [COPY OF TARN]WHERE ((([COPY OF TARN].[Delete this record])=True));"

  tdf.Fields.Delete ("Delete this record") ' error is on this line!!
  tdf.Fields.Refresh

  Set tdf = Nothing
  Set db = Nothing
  Set rs = Nothing




Any help is appreciated.

Many thanks

Tim

Tim
__________________
Tim
 
Old November 5th, 2003, 11:05 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You may be doing this the hard way. You are opening a connection to a database and a table. Once you have opened the table and you have a recordset, the table is locked. I do not know DAO, but I know that you could create a calculated field within the recordset and then use that in a where clause to delete the values that you want. Creating a field can cause too many problems for you.

Or even easier, why not delete the record here

rs.Fields("Delete this record").Value = True

or here

rs.Fields("Delete this record").Value = True



Sal





Similar Threads
Thread Thread Starter Forum Replies Last Post
DB table locking. madhukp Classic ASP Basics 5 June 26th, 2004 06:22 AM
Locking down a table lryckman Access 6 March 1st, 2004 08:50 AM
Table Locking hortoristic SQL Server 2000 1 February 9th, 2004 09:17 PM
Access Problems. Creating a Transition Table rumblepup Access 6 December 23rd, 2003 06:44 PM
Migrating from access 97 to access 2000 Khalifeh Access 12 October 2nd, 2003 02:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.