Solved

Help Needed!!  MS Access/SQL problem

Posted on 2001-08-04
9
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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
 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

630 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