Solved

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

Posted on 2006-11-28
7
217 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
Comment Utility
Probably, you can check recordset.recordcount property?
0
 
LVL 11

Expert Comment

by:Dany Balian
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:tvtech
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
mrdany, that'll do me. Thanks.
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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

7 Experts available now in Live!

Get 1:1 Help Now