473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why runtime error with this line... Set MyTable = MyDB.OpenRecordset("tblOrders", DB_OPEN_TABLE)

MLH
I copied the following code right out of MS Access 2.0
HELP under Index Property Setting example...

Sub Button0_Click ()
Dim MyDB As Database, MyTable As Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyTable = MyDB.OpenRecordset("tblOrders", DB_OPEN_TABLE)
MyTable.Index = "PrimaryKey"
MyTable.Seek "=", 10050
MyTable.Close

End Sub

When I run it, I get an Invalid Operation error on the
Set MyTable line. If tblOrders is a valid attached table,
why does running that line produce an error? I do not
get the same error if substituting a local table (one that
is not attached). BTW, the attachment is from a back
end table to a front end table - both residing on the
same stand-alone workstation.
Nov 13 '05 #1
2 4470
Firstly, make sure you have a reference to the DAO library.
From the code window, choose References on the Tools menu.
Check the box beside:
Microsoft DAO 3.6 Library

Secondly, the constants have changed name. Try dbOpenTable instead of
DB_OPEN_TABLE.

Most importantly, you cannot open a linked table as dbOpenTable. You need to
use dbOpenDynaset. When you do that, the next line will fail, because you
cannot set the Index property of a dynaset type recordset. The code
therefore needs to be rewritten so that it opens a SQL statement, ordered by
the desired field, or limited the desired record. This kind of thing:

strSQL = "SELECT OrderID FROM tblOrders WHERE OrderID = 10050;"
Set MyTable = MyDB.OpenRecordset(strSql)
If not MyTable.EOF Then
MsgBox "Order 10050 was found."
End If
MyTable.Close

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.net> wrote in message
news:f9********************************@4ax.com...
I copied the following code right out of MS Access 2.0
HELP under Index Property Setting example...

Sub Button0_Click ()
Dim MyDB As Database, MyTable As Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyTable = MyDB.OpenRecordset("tblOrders", DB_OPEN_TABLE)
MyTable.Index = "PrimaryKey"
MyTable.Seek "=", 10050
MyTable.Close

End Sub

When I run it, I get an Invalid Operation error on the
Set MyTable line. If tblOrders is a valid attached table,
why does running that line produce an error? I do not
get the same error if substituting a local table (one that
is not attached). BTW, the attachment is from a back
end table to a front end table - both residing on the
same stand-alone workstation.

Nov 13 '05 #2
MLH
Thanks for the heads up on the situation, Allen. Good advice.
xxxxxxxxxxxxxxxxxxxxxx
On Mon, 18 Oct 2004 22:44:51 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:
Firstly, make sure you have a reference to the DAO library.
From the code window, choose References on the Tools menu.
Check the box beside:
Microsoft DAO 3.6 Library

Secondly, the constants have changed name. Try dbOpenTable instead of
DB_OPEN_TABLE.

Most importantly, you cannot open a linked table as dbOpenTable. You need to
use dbOpenDynaset. When you do that, the next line will fail, because you
cannot set the Index property of a dynaset type recordset. The code
therefore needs to be rewritten so that it opens a SQL statement, ordered by
the desired field, or limited the desired record. This kind of thing:

strSQL = "SELECT OrderID FROM tblOrders WHERE OrderID = 10050;"
Set MyTable = MyDB.OpenRecordset(strSql)
If not MyTable.EOF Then
MsgBox "Order 10050 was found."
End If
MyTable.Close


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.