472,792 Members | 4,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,792 software developers and data experts.

Unbound Form: Get PK of Saved Record

This is an embarrassing question to which I should know the answer, but
I am not 100% sure of myself. My applications, whether they are Jet or
Oracle usually deal with reporting on existing apps that others have
done and except for the odd single user app, I don't do many transaction
type applications....

Anyways,

I have an unbound form which is a data entry form for new records or in
"add record" mode. Say this form is for creating requisitions. The
user enters all the criteria in numerous unbound controls. User then
clicks a save button or tool bar item and an insert/append statement
takes place and the table in question, now has a new record. A PK is
created for the new record via an autonumber (or trigger/sequence in
Oracle).

Say the new record is a requisition and the form has a subform for line
items which is enabled with the save procedure. To add these records to
the subform, I'm going to need the PK of the record I've just created.
I would appreciate any comment or alternate approach that is better than
the following approach:

1) Create and run the insert/append SQL statement

2) Use a DAO snapshot recordset (this is A97) and use .movelast to go to
last record.

3) Take the new PK and store it in a form variable or control.

My area of worry is the .movelast method on a multi user database.
Probably very remote, but don't I run the risk of moving last to another
user's new record that was inserted at about the same time as my own?

I need some reassurance or pointing in another direction, thanks very
much in advance.

--
Tim - http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Want some?" - Ditto
Nov 12 '05 #1
4 3797
On Wed, 10 Sep 2003 17:11:06 -0230, Tim Marshall <tm******@Gunner.Sabot.Spam.On.Loaded.FIRE> wrote:
This is an embarrassing question to which I should know the answer, but
I am not 100% sure of myself. My applications, whether they are Jet or
Oracle usually deal with reporting on existing apps that others have
done and except for the odd single user app, I don't do many transaction
type applications....

Anyways,

I have an unbound form which is a data entry form for new records or in
"add record" mode. Say this form is for creating requisitions. The
user enters all the criteria in numerous unbound controls. User then
clicks a save button or tool bar item and an insert/append statement
takes place and the table in question, now has a new record. A PK is
created for the new record via an autonumber (or trigger/sequence in
Oracle).

Say the new record is a requisition and the form has a subform for line
items which is enabled with the save procedure. To add these records to
the subform, I'm going to need the PK of the record I've just created.
I would appreciate any comment or alternate approach that is better than
the following approach:

1) Create and run the insert/append SQL statement

2) Use a DAO snapshot recordset (this is A97) and use .movelast to go to
last record.

3) Take the new PK and store it in a form variable or control.

My area of worry is the .movelast method on a multi user database.
Probably very remote, but don't I run the risk of moving last to another
user's new record that was inserted at about the same time as my own?

I need some reassurance or pointing in another direction, thanks very
much in advance.


Even though the PK is an Autonumber you can predetermine the next available number using
Nz(Dmax("MyID","tblMyTable"))+1
Store this number in a variable and use it directly in your Append SQL statement.
You will need error handling to increment the number if the append fails (another user has added a record since you obtained the next available
number).
Once the append has succeeded, you already have the PK stored in your variable so there is no need for further checking.

This will work with JET, but I don't know about Oracle.
Wayne Gillespie
Gosford NSW Australia
Nov 12 '05 #2
TC
Would it be appropriate to change the PK from autonumber to long, have a
seperate table holding the next available PK value, then get the value from
that table, so you can plug it into the INSERT statement?

TC

"Tim Marshall" <tm******@Gunner.Sabot.Spam.On.Loaded.FIRE> wrote in message
news:3F***************@Gunner.Sabot.Spam.On.Loaded .FIRE...
This is an embarrassing question to which I should know the answer, but
I am not 100% sure of myself. My applications, whether they are Jet or
Oracle usually deal with reporting on existing apps that others have
done and except for the odd single user app, I don't do many transaction
type applications....

Anyways,

I have an unbound form which is a data entry form for new records or in
"add record" mode. Say this form is for creating requisitions. The
user enters all the criteria in numerous unbound controls. User then
clicks a save button or tool bar item and an insert/append statement
takes place and the table in question, now has a new record. A PK is
created for the new record via an autonumber (or trigger/sequence in
Oracle).

Say the new record is a requisition and the form has a subform for line
items which is enabled with the save procedure. To add these records to
the subform, I'm going to need the PK of the record I've just created.
I would appreciate any comment or alternate approach that is better than
the following approach:

1) Create and run the insert/append SQL statement

2) Use a DAO snapshot recordset (this is A97) and use .movelast to go to
last record.

3) Take the new PK and store it in a form variable or control.

My area of worry is the .movelast method on a multi user database.
Probably very remote, but don't I run the risk of moving last to another
user's new record that was inserted at about the same time as my own?

I need some reassurance or pointing in another direction, thanks very
much in advance.

--
Tim - http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Want some?" - Ditto

Nov 12 '05 #3
TC wrote:

Would it be appropriate to change the PK from autonumber to long, have a
seperate table holding the next available PK value, then get the value from
that table, so you can plug it into the INSERT statement?


Bingo, that'll work.

Actually, since I'm doing it in Oracle, I'll have a sequence generator
(in place of the table you suggested) for the PK which is fired by the
save procedure to set up a new number that is then placed in the INSERT
statement as you suggested.

Thanks. This will also solve my problem with .addnew in another
thread. FWIW, in Oracle, to set up the equivalent of an autonumber, you
create a sequence. In some apps, there's one sequence that generates a
number for all PKs used by all tables, in others, you have separate
sequences for separate tables. To have the sequence act like an
Access/Jet autonumber, you then set up a trigger that fires and
populates your PK (or whatever) column/field before or after the insert
takes place.
--
Tim - http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Want some?" - Ditto
Nov 12 '05 #4
Thanks Wayne, I'm filing this for when I do get involved with a Jet app
that has similar transactions. TC provided with an idea as to how I can
do this in Oracle.
--
Tim - http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Want some?" - Ditto
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pierre | last post by:
Hi all, To ease load on a network i close automatically form open with a timer reset by user actions. If the time is expired i go through the collections of form and table and close all those...
3
by: MLH | last post by:
I have a form, bound to a query. Its RecordSource property is a query named frmEnterLienAmounts. The form has a few bound controls and some unbound controls. The unbound controls are calculated...
4
by: Robert | last post by:
Have main form with an unbound subform1 which is used for data entry. Subform1 has a nested continuous unbound subform (subform2) which is used to enter multiple records related to the record being...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
10
by: Matthew Wells | last post by:
Hello. I've converted a bound Access 2000 form which displays data retrieved from an Access 2000 database to an unbound form. Now my hyperlinks don't work. I'm assuming it's because the form...
18
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
11
by: TD | last post by:
I'm looking for input into my decision to switch to ADO and unbound forms. I get tired of having to block all of the ways a user can unknowingly save a record, like using the PageUp, PageDown keys...
2
by: ApexData | last post by:
I have a Single form with its RecordSource set to one table. This form will have only one record that is used for the application setup. I have UnBound TextBoxes on the form. The textboxes will...
4
by: Susan Bricker | last post by:
I have a form that displays record information in Continuous Record display (scrollable list). One of the fields in the record is an Integer value called "rcode" (reason code). But, I don't want...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.