Solved

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

Posted on 2006-11-28
7
220 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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

821 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