PC Review


Reply
Thread Tools Rate Thread

Apply Sequence Number in Append Query

 
 
Scott
Guest
Posts: n/a
 
      25th Jul 2008
Greetings most excellent programmers. First post but love the tons of
messages that have helped so far. So thanks in advance!!!

I have a table with an ID (MyID) which is a sequential number as primary
key. I generate the number from a form with the followoing expression in the
"default" property MyID on the form set to =DMax("MyID","MyIDTable")+1. This
works great when creating new records from the form. I now need to in some
cases load records via Append query ( i have an import from flat file into
temp table, then do append query to move to primary table). When I try to
use this same method in append query to set MyID (via expression on query
field) , it will only insert the first record from append source and then
errors on unique record violation. It's as if the first record gets there
but the DMax("MyID","MyIDTable")+1 can't see the new record and can't
increment MyID on each append row insert?

Any ideas?
 
Reply With Quote
 
 
 
 
bcap
Guest
Posts: n/a
 
      25th Jul 2008
A query is logically an atomic set operation, not a procedural operation,
thus the expression to return the new ID only gets performed once for the
whole operation, hence the duplicate key.

You could try this:

First create a function in a module, such as this:

Function NextId(ByRef Junk As Variant) As Integer

Static intLastId As Integer

If intLastId = 0 Then
intLastId = DMax("ID", "Table3")
End If

intLastId = intLastId + 1
NextId = intLastId

End Function

In your query, append this to MyID:

NextId([some_field])

Where some_field is a field in your temporary table. It doesn't matter what
field.

"Scott" <(E-Mail Removed)> wrote in message
news:95A48849-9C25-4AC6-BFEE-(E-Mail Removed)...
> Greetings most excellent programmers. First post but love the tons of
> messages that have helped so far. So thanks in advance!!!
>
> I have a table with an ID (MyID) which is a sequential number as primary
> key. I generate the number from a form with the followoing expression in
> the
> "default" property MyID on the form set to =DMax("MyID","MyIDTable")+1.
> This
> works great when creating new records from the form. I now need to in
> some
> cases load records via Append query ( i have an import from flat file into
> temp table, then do append query to move to primary table). When I try to
> use this same method in append query to set MyID (via expression on query
> field) , it will only insert the first record from append source and then
> errors on unique record violation. It's as if the first record gets there
> but the DMax("MyID","MyIDTable")+1 can't see the new record and can't
> increment MyID on each append row insert?
>
> Any ideas?



 
Reply With Quote
 
bcap
Guest
Posts: n/a
 
      25th Jul 2008
Sorry, I should have said that "ID" and "Table3" were just the stuff that I
created to play with this. You should obviously replace with your own:

DMax("MyID","MyIDTable")

"bcap" <(E-Mail Removed)> wrote in message
news:48898a05$0$2518$(E-Mail Removed)...
>A query is logically an atomic set operation, not a procedural operation,
>thus the expression to return the new ID only gets performed once for the
>whole operation, hence the duplicate key.
>
> You could try this:
>
> First create a function in a module, such as this:
>
> Function NextId(ByRef Junk As Variant) As Integer
>
> Static intLastId As Integer
>
> If intLastId = 0 Then
> intLastId = DMax("ID", "Table3")
> End If
>
> intLastId = intLastId + 1
> NextId = intLastId
>
> End Function
>
> In your query, append this to MyID:
>
> NextId([some_field])
>
> Where some_field is a field in your temporary table. It doesn't matter
> what field.
>
> "Scott" <(E-Mail Removed)> wrote in message
> news:95A48849-9C25-4AC6-BFEE-(E-Mail Removed)...
>> Greetings most excellent programmers. First post but love the tons of
>> messages that have helped so far. So thanks in advance!!!
>>
>> I have a table with an ID (MyID) which is a sequential number as primary
>> key. I generate the number from a form with the followoing expression in
>> the
>> "default" property MyID on the form set to =DMax("MyID","MyIDTable")+1.
>> This
>> works great when creating new records from the form. I now need to in
>> some
>> cases load records via Append query ( i have an import from flat file
>> into
>> temp table, then do append query to move to primary table). When I try
>> to
>> use this same method in append query to set MyID (via expression on
>> query
>> field) , it will only insert the first record from append source and then
>> errors on unique record violation. It's as if the first record gets
>> there
>> but the DMax("MyID","MyIDTable")+1 can't see the new record and can't
>> increment MyID on each append row insert?
>>
>> Any ideas?

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Append Query to update Sequence Generator in Oracle Jim Microsoft Access Queries 9 22nd Dec 2007 07:04 PM
How do I keep a correct sequence in an append query? =?Utf-8?B?UGFt?= Microsoft Access Queries 1 27th Feb 2007 07:37 PM
How to get a sequence number in a query doyle60@aol.com Microsoft Access VBA Modules 5 4th Apr 2006 04:49 PM
Append Query w/sequence.NextVal to Oracle DB? =?Utf-8?B?SmFjaw==?= Microsoft Access Queries 2 22nd Mar 2005 09:29 PM
Append Query... Can't Create a Unique Number to Append Vance Microsoft Access Queries 8 17th Dec 2003 11:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:49 PM.