Source language: Translate to:

Adding a new record without overwriting an existing one

Questions about our Advanced Database plug-in

Moderator: Neosoft Support

Adding a new record without overwriting an existing one

Postby DantesGame » Tue Dec 08, 2015 10:00 am

Hi all,

I'm sorry if this seems like a really silly question but, how can I add a new record to my Access db without overwriting the current record being displayed in my contact manager?

I've gone through the DBPro tutorial, have read through the help files fairly thoroughly, and have my project working quite well all the way up to this point. If I have a record open (an active record), I can overwrite the data in each field (name, profession, etc. etc. etc.) and use the Action Command dbpAddRecord "My_contacts" "Demographics" to add the new record, but it overwrites the existing record.

In the DBPro tutorial they walk you through opening the database via a grid and the "add record" button is already buried in the code (I can't see what Action Command it's set to because the button doesn't appear to be accessible other than at runtime) but it seems to create the new record on a new line in the database. This is what I want to achieve, obviously.

This seems like something really basic I'm overlooking and any help would be appreciated.
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm

Re: Adding a new record without overwriting an existing one

Postby stu » Tue Dec 08, 2015 10:03 am

Add more control to your applications by using dbpExecSQL, throw the queries yourself so you know whats going on...

INSERT INTO tblOne (Field1, Field2, Field3) VALUES ([var1], [var2], [var3]);
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Adding a new record without overwriting an existing one

Postby DantesGame » Tue Dec 08, 2015 10:47 am

Thanks, Stu. I'll give that a try. I'm not super-versed in SQL but learn quickly.

One difference I noticed between the tutorial database and mine is that they seem to have a blank field at the end or beginning of the table. If I land on that (using the tutorial interface) and create a new record, it's added normally. I'm wondering if that's the key I'm missing..?
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm

Re: Adding a new record without overwriting an existing one

Postby Gaev » Tue Dec 08, 2015 10:55 am

DantesGame:

Have you tried invoking the dbpAddrecord command BEFORE making the changes to the form fields ?

According to the Help information for the command ...
Purpose:
Add a new empty record to a table.


If you want to retain the initial values of the fields for the newly created record ...

a) use dbpRecordToVar to save the ontents of the current record

b) invoke the afore mentioned dbpAddrecord

c) use dbpVarToRecord to populate the newly created record with the contents saved in (a)
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Adding a new record without overwriting an existing one

Postby DantesGame » Tue Dec 08, 2015 11:11 am

Hi Gaev,

It's funny 'cause I *just did this* before checking back here and that worked. I went back into the tutorial and really broke down how they setup their commands and db. I even found where I could see the other commands for the buttons that get added by the grid view (by watching the debugger closely!).

So long story short, I open my db, page through a couple of records, clicked my Add Record button, got a blank field, completed it, and then clicked Add Record again and it saved without overwriting/deleting any other records!

Thank you both for the suggestions!

-Efrem
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm

Re: Adding a new record without overwriting an existing one

Postby Gaev » Tue Dec 08, 2015 12:08 pm

DantesGame:

I open my db, page through a couple of records, clicked my Add Record button, got a blank field, completed it, and then clicked Add Record again and it saved without overwriting/deleting any other records!

Don't use dbpAddrecord twice ... you will then create an additional "empty record" (which may not be immediately visible) ... but after a while, your Table will contain lots of empty records.

When you ask to add a new record, any changes previously made to the current record will be automatically saved (updated) unless you have set dbpSetAutoEdit to "No" ... if you have, then do dbpSaveEdits before any dbpAddrecord
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Adding a new record without overwriting an existing one

Postby DantesGame » Tue Dec 08, 2015 12:40 pm

That's good to know, Gaev. I guess I was thinking I had to click "Add Record" again to save what I just entered.
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm


Return to NeoBookDBPro

Who is online

Users browsing this forum: Bing [Bot] and 2 guests