Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MDB: To .AddNew, or .Edit, that is the question

Posted on 2006-11-28
7
Medium Priority
?
225 Views
Last Modified: 2010-04-30
Hi,

   How can I tell when a user is creating a new record, or just editing an existing record in a DAO database?

   Tried using my code to determine a textbox/combox change, but it no workies. Anyone have a foolproof way to do this?

   Thanks.
0
Comment
Question by:tvtech
7 Comments
 
LVL 28

Expert Comment

by:Ark
ID: 18033608
Probably, you can check recordset.recordcount property?
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 18036016
if u have a primary key in the table...
the primary key will have a value if u're editing...
so,
maybe u can check it on the before_update event of the recordset...

hope this helps...
cheers

dan
0
 
LVL 12

Expert Comment

by:jkaios
ID: 18040697
Check the EditMode property to determine whether the current status is Adding or Editing as follows:

   If Data1.Recordset.EditMode = dbEditAdd Then
      Label1.Caption = "Adding"
   ElseIf Data1.Recordset.EditMode = dbEditInProgress Then
      Label1.Caption = "Editing"
   End If
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:tvtech
ID: 18043394
Thanks for the comments.

jkaios, I don't use a Data1 control in myc code, so can't use that method.

mrdany, yes, my code does use Primary keys for each record. Just unsure how to go about retrieving it before user starts adding, or editing.

Thanks.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 18043619
hey tvtech

i just checked the dao object... and in the recordset you have sthg called editmode

try this

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = OpenDatabase("c:\db.mdb")
Set rs = db.OpenRecordset("select * from table")
r.MoveFirst
r.Edit
MsgBox r.EditMode   '<<< this will give you 1

'and then try this

r.addnew
msgbox r.editmode  '<<< this will give you 2


hope this helps..
cheers

dan
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 1400 total points
ID: 18043656
sorry, please correct my typos..
dim rs as dao.recordset should be dim R as dao.recordset
and set rs=db.openrecordset should be set R=db.openrecordset..

cheers

dan
0
 

Author Comment

by:tvtech
ID: 18049796
mrdany, that'll do me. Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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

824 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