Help: Forms using linked tables

V

Vern Shellman

We've got a form in Access 97 SR-2 that works fine with local tables.
The pertinent VB code populating a combo box looks like this:


Private Function ShowMOFInfo()
Dim db As Database
Dim rec As Recordset
Dim ccode As Integer
Dim strAD As String


On Error GoTo smiErrorHandler
Set db = DBEngine.Workspaces(0).Databases(0)
Set rec = db.OpenRecordset("tblMOF")
rec.Index = "PrimaryKey"
rec.Seek "=", Me!cboStudyNumber
If rec.NoMatch Then ....

When the same table is linked to an external database the form fails.
I'm not much of a VB progammer but I've learned that the problem is with
the .Seek function on linked tables. So I've tried using FindFirst in
the following manner:


On Error GoTo smiErrorHandler
Set db = DBEngine.Workspaces(0).Databases(0)
Set rec = db.OpenRecordset("tblMOF")
rec.FindFirst "StudyNumber = '" & Me![StudyNumber]& "'"
If rec.NoMatch Then ....

Looking in the Immediate Window, Rec.Fields.Count finds the correct
number of fields but I'm seeing a lot of errors declaring:

<Operation is not supported for this type of object>.

Also, error trapping gives:

"run-time error '13'; type mismatch".

However, creating a new form that pulls data from the same remote table
works, so I don't think it's a datatype issue.

What am I doing wrong?

Thanks in advance for any suggestions on how we might solve this
problem.
 
A

Allen Browne

Hi Vern.

You can solve the problem by specifying you want to open a dbDynaset type
recordset, and use FindFirst (not Seek).

If you don't specify what kind of recordset you want to open, Access gives
you a dynaset type if you open an attached table, query or SQL statement,
but a Table type if you open a recordset based on a local table. This
inconsistency is likely to break your code if the tables are moved, etc.,
just as you found.

Try:
Set rec = db.OpenRecordset("tblMOF", dbOpenDynaset)
rec.FindFirst "StudyNumber = '" & Me![StudyNumber] & "'"

BTW, if StudyNumber is actually a Number field (not a Text field, drop the
extra quotes, i.e.:
rec.FindFirst "StudyNumber = '" & Me![StudyNumber]& "'"
In the case where StudyNumber is blank on the form (e.g. at a new record),
the criteria will be mal-formed, so you may want to use:
rec.FindFirst "StudyNumber = " & Nz(Me![StudyNumber], 0)
 

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

Similar Threads

Access Passing the value to a table 1
Seek Method for Multiple-field index 2
Using rec.seek to avoid upload of multiple duplicate entries 1
Access 2002 1
Forms & Recordsets 10
FindFirst Problem 1
Linked Files 3
Back end/Front End 1

Top