Help Needed!! MS Access/SQL problem

This is worth alot, since this needs to be answered quickly.

I have a MS Access DB, which I upgraded to the SQL Server.  I can open the SQL server fine, but when I hit a certain point in my code it fails with the error "Run-time error '3251'"  "Operation is not supported for this type of object"

Here is the code:
Dim rstcallserv As Recordset

If BttnStatus(FormNumber, LastBttn) = "ADD" Then
    If Form_INCIDENT.Incno <> 0 And Form_INCIDENT.Incno <> "" Then
        Set rstcallserv = DBBACKEND.OpenRecordset("CALLSERV", dbOpenDynaset, dbSeeChanges)
         With rstcallserv
            rstcallserv.Index = "INCNO" <<Offending code
            rstcallserv.Seek "=", Form_INCIDENT.Incno << Offending code
            Form_INCIDENT.details1 = !details1
            Form_INCIDENT.OCCFrom = !DATECOMP
            Form_INCIDENT.OCCTo = !DATECOMP
            Form_INCIDENT.ReviewDate = !DATECOMP
            Form_INCIDENT.TimeFrom = !TIMECOMP
            Form_INCIDENT.TimeTo = !TIMECOMP
        End With
    End If
End If
Me!Incno.BackColor = 16777215
End Sub


The error pops up at the .index statement, and if I comment that out, it appears on the .seek as well.  I looked through MSDN, and they suggest it could be because the table is read-only.  But its not.  This code works perfectly in an all MS-Access setup.  Is there a substitute to the .index & .seek command for sql?

What this code does, is after you put in an incident number, it then retrieves data in another table based off of that incident number.  

Please advise..
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It is more efficient and flexible to perform all database access to sql server via stored procedures. It gets round the problem of binding the client application to the database structure as well as making testing a lot easier. And will probably get round problems like this.

In this case the SP would just take the Incno as a parameter and just return the info that needs displaying - so locking records for less time and will use the sql server query optimiser to cache the query plan.

just a couple of questions first.

-when you use DBBACKEND, is this a connection or is this a DAO.Database object?
-is CALLSERV a storedprocedure or a table? i am guessing it's a table.
-a97, a2k, or axp?
-using ado or dao?

depending on your answers, i would change some of the ways you do things. personally, i would create a stored procedure that returns the result you are looking for. open a connection to the sql server and then open a recordset based of the connection and the stored procedure. you don't really need a stored procedure, it'd just be a bit faster though i don't know if you'd ever notice the difference...

but aside from all of that. try this code in place of what you had.

       Set rstcallserv = DBBACKEND.OpenRecordset("SELECT * " _
            & "FROM CALLSERV " _
            & "WHERE Inco = " & Form_INCIDENT.Incno, _
            dbOpenDynaset, _
        With rstcallserv
           'you shouldn't need this .Edit
           Form_INCIDENT.details1 = !details1
           Form_INCIDENT.OCCFrom = !DATECOMP
           Form_INCIDENT.OCCTo = !DATECOMP
           Form_INCIDENT.ReviewDate = !DATECOMP
           Form_INCIDENT.TimeFrom = !TIMECOMP
           Form_INCIDENT.TimeTo = !TIMECOMP
       End With

let me know if this doesn't help or you need more help...

I would remove the rstcallserv lines after the with statement.
        With rstcallserv
           .Index = "INCNO"
           .Seek "=", Form_INCIDENT.Incno

With a "With" statement it is not necessary to specify the object repeatedly.
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

K-9Author Commented:
Thanks for the help so far.. Dovholuk, when I try your suggestion it gives me an error "Run-time error 3464" "Data type mismatch in criteria expression"  Both incno fields in the callserv & this table are set to "Text"  I am running Access2000 as a front end.  And Callserv is a table.

I also got a "with" error when I had the with rstcallserv statement in there.  I took it out & used
Form_INCIDENT.details1 = rstcallserv!details1

Also, I know this may sound like a dumb question to u guys, but how can I create a stored procedure, and how do I call it from access?

Thanks for your help so far!
the 3464 error due to INCNO being text so buffer it with apostrophes to make it work properly. such as:

Set rstcallserv = DBBACKEND.OpenRecordset("SELECT * " _
           & "FROM CALLSERV " _
           & "WHERE Inco = '" & Form_INCIDENT.Incno & "'", _
           dbOpenDynaset, _

in your with you are using the recordset so i'm surprised what you wrote the second time worked. but as long as it does you'll be all set.

creating a stored procedure you need to have access to the server or you need to a passthrough query and use t-sql.

try running:

create stored procedure THIS_IS_A_TEST

then to run the stored procedure, run another passthrough query which just calls the procedure:


i gotta jet, i'll check back in later...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What version of Access, and if 2K are you using an ADP?

The original error message you're getting seems to indicate you have an ADO recordset rather than a DAO recordset.  ADO recordsets have no Seek method.

When you define your RS you can specify a DAO.Recordset or ADODB.Recordset (assuming the proper references are in your db)
K-9Author Commented:
TY very much for the help.. It works good :)  

I have another simple question, Ill post it here, but I can give you points for it as well.  I created a simple find button on the access form.  Well, it seems toe work when I type in a name that I know exists, however if I type one that doesn't exists, or do a to only match "part of the field" it will just hang.  I can press ctrl+break to stop the search, but pushing ctrl+alt+delete, shows it "not responding" in the task manager.  Is there another way around this?

Thanks again!
what i do to match "part of a field" is i create an if statement that determines if the user is looking for an exact match or any part of the field. then in the appropriate if else statement i put something like:

'You have 1 form named MyForm
'You have 1 control named txtMyTextBox (or whatever)
'You have 1 checkbox named chkMatchExact labeled "Match Exactly" or something similiar
'an open connection to DBBACKEND somewhere on an SQL server 'since you're using SQL server
'    i thought i'd build this example around SQL server
'a table named CALLSERV with a field named INCNO

if me!chkMatchExact = true then
     set rs = DBBACKEND.OpenRecordset("SELECT * FROM CALLSERV WHERE INCNO = '" & me!txtMyTextBox & "'")
     'the user wants to match any part of the field
     set rs = DBBACKEND.OpenRecordset("SELECT * FROM CALLSERV WHERE INCNO like '%" & me!txtMyTextBox & "%'")
end if

if not rs.eof then
    'the recordset is NOT empty so do something...
end if

help any? need more help?

K-9Author Commented:
Well it does help, but I have like 20 different text boxes on that form, and have about 50 other forms as well in this DB.  Its quite large.  I hope there's an easier way to doing this.  

I ran another test, and it seems to sometimes find a match, sometimes just hang, even if the data exists in that field.  Do I need to set something up at the sql server to allow the searches to run at 100% ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.