To clarify, this code is in the frmRunningTasks form, and in this same form
is that "New" command button referred to in this code. As you'll immediately
resolve, this then opens the frmRunningTasksAddNewRec form from which I add
new records. I want this process to be the only way possible for us to add a
new record to the database.
Thanks again.
"Richard" wrote:
> Thanks John/David,
>
> I've managed to export all the data and import it into a new table.
>
> I have all my ID numbers in a Long Integer number field now. What I'd like
> to do is generate this so-called Auto-number (as per David's code) whenever I
> click on the "New" command button on one of my forms. I'd like to have the
> new number generated ONLY when we click on that button. If I were to add the
> code in the On Open event, for example, a new number would be generated any
> time I opened that form.
>
> The following code gives me a "Sub or function not defined" error:
>
> Private Sub cmdAddRecord_Click()
> On Error GoTo Err_cmdAddRecord_Click
>
> Dim stDocName As String
> Dim stLinkCriteria As String
>
> stDocName = "frmRunningTasksAddNewRec"
> DoCmd.OpenForm stDocName, , , stLinkCriteria
> [txtID] = MAX([tblRunningTasks]![ID]) + 1
>
> Exit_cmdAddRecord_Click:
> Exit Sub
>
> Err_cmdAddRecord_Click:
> MsgBox Err.Description
> Resume Exit_cmdAddRecord_Click
>
> End Sub
>
>
> I know I'm close, almost there. Or would you guys suggest I do this some
> other way?
>
>
> "John Vinson" wrote:
>
> > On Mon, 16 Oct 2006 05:39:01 -0700, Richard
> > <(E-Mail Removed)> wrote:
> >
> > >Hello everyone,
> > >
> > >I have a ID field which is a Auto-number field.
> > >
> > >Don't know what happened, but record number "655" now shows as
> > >"4.2926103E+07". Somehow, this ID seems to have got corrupted.
> > >
> > >Now all our work orders are numbered as per this/these ID numbers, so
> > >obviously, I want to try to save these numbers... what are my options?
> > >
> > >Thanks.
> >
> > As David says... you should NOT be using Autonumbers for this purpose.
> > You just found out one reason why... <g>
> >
> > Did you Replicate the database recently? If so, it will change all
> > Autonumber fields to Random. Each new autonumber will be somewhere in
> > the range -2^31 to +2^31-1. Or, somehow the table definition might
> > have been changed to make the autonumber field Random.
> >
> > I would suggest creating a new table with a Long Integer primary key;
> > run an Append query to migrate your existing data into it. You'll be
> > able to edit this record in the new table. You will need to
> > reestablish all your relationships (dropping them from the old table
> > and creating new ones from the new) and follow David's advice about
> > programmatically assigning new ID numbers.
> >
> > John W. Vinson[MVP]
> >
|