Solved

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

Posted on 2006-11-28
7
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month3 days, 21 hours left to enroll

630 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