Solved

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

Posted on 2006-11-28
7
218 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 27

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

867 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

18 Experts available now in Live!

Get 1:1 Help Now