Link to home
Start Free TrialLog in
Avatar of TerenceHewett
TerenceHewett

asked on

Run-time error '3219': Invalid operation

Hi experts,

I have the following code that puts an ID into a field in the table tblPSX.  

Dim db As Database
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblPSX", dbOpenTable)

    rs.MoveFirst
    'Updating the records
    Do Until rs.EOF = True
    With rs
    .Edit
    PS=!PSID
   .Update
   End With
   rs.MoveNext
   Loop
     
    Set rs = Nothing
    Set db = Nothing


The code works fine if tblPSX is not a linked table, but if the table is linked I get the following message:

Run-time error '3219': Invalid operation

When I debug, the highlighted text is "Set rs = CurrentDb.OpenRecordset("tblPSX", dbOpenTable)".

Can anyone help?

Thank you.
Terry


ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thenelson
thenelson

When it is a linked table it is not in the current Db. The easiest way around this is open a query to the table instead:
Set rs = CurrentDb.OpenRecordset("Select * From tblPSX")

BTW: You are not using "db" so you don't need:
Dim db As Database
    Set db = Nothing
Researching further, you should be able to open a recordset on a linked table. Can you open the tblPSX from the front end?
me thinks, linked table is from SQL or other db that uses ODBC
Avatar of TerenceHewett

ASKER

As always, a first class response and I am very grateful.
Thanks for all posts - Cap, the following worked a treat:

Set rs = CurrentDb.OpenRecordset("tblPSX",dbopendynaset)


Regards.
Terry