PC Review


Reply
Thread Tools Rate Thread

"add" mode not going to end of table

 
 
Dave Couch
Guest
Posts: n/a
 
      14th Apr 2009
I have a macro that opens a form in add mode for the table Transmittals.
However, when I try to save the record, the record number is somewhere in the
middle of the record numbers and will not let me save. I have tried the
"repair and compact" with no help. I don't appear to have any "breaks" in
the table. Any help would be appreciated.

Dave Couch
 
Reply With Quote
 
 
 
 
Dave Couch
Guest
Posts: n/a
 
      14th Apr 2009
I was able to copy the table and then rename it. That seemed to fix the
problem.

"Dave Couch" wrote:

> I have a macro that opens a form in add mode for the table Transmittals.
> However, when I try to save the record, the record number is somewhere in the
> middle of the record numbers and will not let me save. I have tried the
> "repair and compact" with no help. I don't appear to have any "breaks" in
> the table. Any help would be appreciated.
>
> Dave Couch

 
Reply With Quote
 
Graham Mandeno
Guest
Posts: n/a
 
      14th Apr 2009
Hi Dave

I'm afraid I'm going to give you more questions than answers! :-)

What sort of field is your record number? Is it an AutoNumber? If so, is
its NewValues property set to Increment or Random?

If it is not an AutoNumber, how are new values generated?

When you say there are no "breaks" in the table, do you mean there are no
gaps in the record number sequence? If so, are these new records being
created with the same values as existing records?

Is the record number field the primary key of your table?

If the field in question is an incremental autonumber and is the primary
key, then the following function will reset the "seed" to one greater than
the current maximum value:

Public Function ResetAutonumber( _
sTable As String, _
Optional sField As String, _
Optional lSeed As Long _
) As Long
'sTable = Table containing autonumber field
'sField = Name of the autonumber field
' (default is the first Autonumber field found in the table)
'lSeed = Long integer value you want to use for next AutoNumber
' (default is one more than the current maximum)
Dim cnn As Object 'ADODB.Connection
Dim cat As Object 'ADOX.Catalog
Dim col As Object 'ADOX.Column
Dim tbl As Object 'ADOX.Table
Dim sRemoteTable As String
On Error GoTo ProcErr
Set cat = CreateObject("ADOX.Catalog")
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables(sTable)
If tbl.Type = "LINK" Then
Set cnn = CreateObject("ADODB.Connection")
cnn.Open _
CurrentProject.Connection.ConnectionString & ";" & _
"Data Source=" & _
tbl.Properties("Jet OLEDB:Link Datasource")
cat.ActiveConnection = cnn
sRemoteTable = tbl.Properties("Jet OLEDB:Remote Table Name")
Set tbl = cat.Tables(sRemoteTable)
End If
If Len(sField) = 0 Then
For Each col In tbl.Columns
If col.Properties("AutoIncrement") Then
sField = col.Name
Exit For
End If
Next
If Len(sField) = 0 Then GoTo ProcEnd
Else
Set col = tbl.Columns(sField)
End If
If lSeed = 0 Then
lSeed = Nz(DMax(sField, sTable), 0) + 1
End If
col.Properties("Seed") = lSeed
ResetAutonumber = lSeed
ProcEnd:
On Error Resume Next
If Not cnn Is Nothing Then
cnn.Close
Set cnn = Nothing
End If
Set col = Nothing
Set tbl = Nothing
Set cat = Nothing
Exit Function
ProcErr:
MsgBox Err.Description
Resume ProcEnd
End Function

--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand


"Dave Couch" <(E-Mail Removed)> wrote in message
news:008F91E7-A2D7-4F8B-A828-(E-Mail Removed)...
>I have a macro that opens a form in add mode for the table Transmittals.
> However, when I try to save the record, the record number is somewhere in
> the
> middle of the record numbers and will not let me save. I have tried the
> "repair and compact" with no help. I don't appear to have any "breaks" in
> the table. Any help would be appreciated.
>
> Dave Couch



 
Reply With Quote
 
Dave Couch
Guest
Posts: n/a
 
      14th Apr 2009
Thanks, Graham, it turned out to be simpler. I just copied the file, then
deleted the old one and renamed the copy. That seemed to fix the problem.

Dave

"Graham Mandeno" wrote:

> Hi Dave
>
> I'm afraid I'm going to give you more questions than answers! :-)
>
> What sort of field is your record number? Is it an AutoNumber? If so, is
> its NewValues property set to Increment or Random?
>
> If it is not an AutoNumber, how are new values generated?
>
> When you say there are no "breaks" in the table, do you mean there are no
> gaps in the record number sequence? If so, are these new records being
> created with the same values as existing records?
>
> Is the record number field the primary key of your table?
>
> If the field in question is an incremental autonumber and is the primary
> key, then the following function will reset the "seed" to one greater than
> the current maximum value:
>
> Public Function ResetAutonumber( _
> sTable As String, _
> Optional sField As String, _
> Optional lSeed As Long _
> ) As Long
> 'sTable = Table containing autonumber field
> 'sField = Name of the autonumber field
> ' (default is the first Autonumber field found in the table)
> 'lSeed = Long integer value you want to use for next AutoNumber
> ' (default is one more than the current maximum)
> Dim cnn As Object 'ADODB.Connection
> Dim cat As Object 'ADOX.Catalog
> Dim col As Object 'ADOX.Column
> Dim tbl As Object 'ADOX.Table
> Dim sRemoteTable As String
> On Error GoTo ProcErr
> Set cat = CreateObject("ADOX.Catalog")
> cat.ActiveConnection = CurrentProject.Connection
> Set tbl = cat.Tables(sTable)
> If tbl.Type = "LINK" Then
> Set cnn = CreateObject("ADODB.Connection")
> cnn.Open _
> CurrentProject.Connection.ConnectionString & ";" & _
> "Data Source=" & _
> tbl.Properties("Jet OLEDB:Link Datasource")
> cat.ActiveConnection = cnn
> sRemoteTable = tbl.Properties("Jet OLEDB:Remote Table Name")
> Set tbl = cat.Tables(sRemoteTable)
> End If
> If Len(sField) = 0 Then
> For Each col In tbl.Columns
> If col.Properties("AutoIncrement") Then
> sField = col.Name
> Exit For
> End If
> Next
> If Len(sField) = 0 Then GoTo ProcEnd
> Else
> Set col = tbl.Columns(sField)
> End If
> If lSeed = 0 Then
> lSeed = Nz(DMax(sField, sTable), 0) + 1
> End If
> col.Properties("Seed") = lSeed
> ResetAutonumber = lSeed
> ProcEnd:
> On Error Resume Next
> If Not cnn Is Nothing Then
> cnn.Close
> Set cnn = Nothing
> End If
> Set col = Nothing
> Set tbl = Nothing
> Set cat = Nothing
> Exit Function
> ProcErr:
> MsgBox Err.Description
> Resume ProcEnd
> End Function
>
> --
> Good Luck :-)
>
> Graham Mandeno [Access MVP]
> Auckland, New Zealand
>
>
> "Dave Couch" <(E-Mail Removed)> wrote in message
> news:008F91E7-A2D7-4F8B-A828-(E-Mail Removed)...
> >I have a macro that opens a form in add mode for the table Transmittals.
> > However, when I try to save the record, the record number is somewhere in
> > the
> > middle of the record numbers and will not let me save. I have tried the
> > "repair and compact" with no help. I don't appear to have any "breaks" in
> > the table. Any help would be appreciated.
> >
> > Dave Couch

>
>
>

 
Reply With Quote
 
YESENIA MERCADO
Guest
Posts: n/a
 
      15th Apr 2009

"Dave Couch" <(E-Mail Removed)> wrote in message
news:008F91E7-A2D7-4F8B-A828-(E-Mail Removed)...
>I have a macro that opens a form in add mode for the table Transmittals.
> However, when I try to save the record, the record number is somewhere in
> the
> middle of the record numbers and will not let me save. I have tried the
> "repair and compact" with no help. I don't appear to have any "breaks" in
> the table. Any help would be appreciated.
>
> Dave Couch


 
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
Subject: Vista question about "compatibility mode" and "safe mode" Ray Windows Vista General Discussion 1 9th May 2008 02:03 PM
How to setup "per target-mode-SCSI-operation DMA" for "target mode" data transfer with **ScsiPort Miniport** driver model? Shailesh Chaudhari Windows XP Drivers 0 23rd Aug 2005 03:19 PM
ask for APIs about change smartphone mode like "Slient" ," Flight","OutDoor" Liren Zhao Microsoft Dot NET Compact Framework 5 3rd Jan 2005 11:53 PM
What is the difference between "cache mode" and "offline mode" in Outlook 2003? Pavel Nagaev Microsoft Outlook 2 4th Jun 2004 06:55 PM
connect to share in "safe w/networking" mode but not in "normal" mode John Burnham Windows XP Networking 1 25th Sep 2003 02:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:58 PM.