Solved

Help Needed!!  MS Access/SQL problem

Posted on 2001-08-04
9
322 Views
Last Modified: 2008-03-10
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
           
            .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
        rstcallserv.Close
       
    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..
0
Comment
Question by:K-9
9 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6351707
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.

0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6351714
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, _
            dbSeeChanges)
        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...

dovholuk
0
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6351761
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.
0
 

Author Comment

by:K-9
ID: 6351860
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
etc...

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!
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 8

Accepted Solution

by:
dovholuk earned 300 total points
ID: 6352004
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, _
           dbSeeChanges)


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
SELECT * FROM CALLSERV

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

THIS_IS_A_TEST

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

dovholuk
0
 
LVL 5

Expert Comment

by:dgorin
ID: 6354278
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)
0
 

Author Comment

by:K-9
ID: 6356940
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!
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6357282
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:

'(ASSUME THE FOLLOWING:)
'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 & "'")
else
     '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?

dovholuk
0
 

Author Comment

by:K-9
ID: 6357506
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% ?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now