[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Editing in ADO Code

Posted on 2000-02-08
11
Medium Priority
?
241 Views
Last Modified: 2012-05-04
I have used Data1.Recordset.Edit for Editing record in DAO.
Now i am trying to use ADODB.Connection with ADODB.Recordset. I want to check the Status of the Recordset (EditMode) during Update. But I didn't get Edit Properties for the ADODB.Recordset.

How Can i check EDITMODE for Recordset if it's in Editmode ?
0
Comment
Question by:thangaraj
  • 7
  • 4
11 Comments
 
LVL 2

Accepted Solution

by:
p_biggelaar earned 150 total points
ID: 2499550
First of all, you can check the EditMode property to see whether some kind of edit is pending:

xx=rs.Editmode

Returnvalues are:
0: adEditNone
1: adEditInProgress
2: adEditAdd
4: adEditDelete

If you want to know whether you can update your recordset use :

xx=rs.Supports(adUpdate)

It will return true for an updatable recordset. See the MSDN library for the other conditions you can check with the Supports Method (adDelete, adAddNew etc...)
0
 

Author Comment

by:thangaraj
ID: 2499649
How Could make Editinprogress. It means
like Data1.Recordset.Edit in DAO.

Any properties in ADO ?

0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2499775
is read-only and informs you whether there is no edit going on, or that the addnew command has been invoked, but the record is not yet saved (adEditAdd) etc...

When your recordset supports update (see proposed answer), you should be able to edit records without calling something like Edit in DAO. Just go ahead and do it  (though remember to throw in an rs.Update to commit the changes)

If the recordset is not updatable, try playing with CursorLocation, CursorType and LockType. This code for example will create an updatable dynamic recordset, with a clientside cursor:

    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenDynamic
    rs.LockType = adLockBatchOptimistic
    rs.Open "Select * from table", cnnActive
'Now I can go ahead and edit my data:
    rs.Fields(0).Value="New Value"
    rs.Fields(1).Value=0
    rs.Update
    rs.Close

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2499785
Sorry, in my Copy & Paste action from Word, I forgot to include the first line of my comment. Here we go:

No. You don't have to explicitly tell the recordset to go into editmode. The Editmode property in ADO is read-only and informs you whether there is no edit going on, or that the addnew command has been invoked, but the record is not yet saved (adEditAdd) etc...

When your recordset supports update (see proposed answer), you should be able to edit records without calling something like Edit in DAO. Just go ahead and do it  (though remember to throw in an rs.Update to commit the changes)

If the recordset is not updatable, try playing with CursorLocation, CursorType and LockType. This code for example will create an updatable dynamic recordset, with a clientside cursor:

    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenDynamic
    rs.LockType = adLockBatchOptimistic
    rs.Open "Select * from table", cnnActive
'Now I can go ahead and edit my data:
    rs.Fields(0).Value="New Value"
    rs.Fields(1).Value=0
    rs.Update
    rs.Close

Good luck!

0
 

Author Comment

by:thangaraj
ID: 2499965
So When will get EDITMODE = editinprogress ?

So, U mean there is no way to make Recordset into EDITMODE like ADDNEW ?
0
 

Author Comment

by:thangaraj
ID: 2499982
I have EDIT Button in the Toolbar. Now I am making True/False the LOCKED Property of the TEXT BOX while EDIT and ADDNEW.

But in DAO, I have done like ADDNEW, EDIT. So, we can get Recordset.EDITMODE = 0,1,2 respectively. This same i am trying to do in ADO.
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2500107
Editmode will return adEditInProgress after you made changes, but before you committed data:

    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenDynamic
    rs.LockType = adLockBatchOptimistic
    rs.Open "Select * from table", cnnActive
'Now I can go ahead and edit my data:

'rs.Editmode = adEditNone    
    rs.Fields(0).Value="New Value"
'rs.Editmode = adEditInProgress
    rs.Fields(1).Value=0
'rs.Editmode = adEditInProgress
    rs.Update
'rs.Editmode=adEditNone
    rs.Close

If you want the user to be able to toggle between editmode and viewmode, you'll have to write some code, simply locking the editboxes at the proper time. You don't have to worry about the underlying code for editing, because nothing will be edited. Even if you want to be careful and make sure that nothing gets edited you can use a boolean variable that indicates whether edit/addnew is allowed and check the value of the boolean before you execute any edit or addnew code.

If you want to display whether the current recordset can be edited, or can only be viewed, use the Supports method.
To add a new record, you still have to use syntax like:

rs.Addnew
rs.fields(0)="New record"
rs.Update
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2500129
So, in short:
- to get a recordset into editmode -> do nothing special. Simply assign new values to your fields and commit the changes by calling the Update method. It will be in editmode as long as you opened a recordset that supports adUpdate

- to get a recordset into addmode -> first call the AddNew method. (Make sure the recordset supports adAddNew)

- to delete a record, use the delete method

- to make sure a record cannot be edited or added either open the recordset (using the default locktype), so that supports(adUpdate) and Supports(adAddNew) will return false OR use variables to hold the mode that you want to allow and write some code to programmatically control the behavior.
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2500161
The way you could use the editmode property is actually the same as you told you were doing in DAO.
0
 

Author Comment

by:thangaraj
ID: 2502973
Thank U Very Much
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2503235
you're welcome
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

640 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