如何从Access数据库重置自动增量字段 [英] How to reset AutoIncrement field from Access Database

查看:90
本文介绍了如何从Access数据库重置自动增量字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重置特定字段的自动增量"字段. 原因是它得到的计数会自动填充到案例编号中.但是,当它出现在午夜12/31/2013 11:59:00 PM时,我想自动从零开始重新递增.

I am trying to reset the Autoincrement field of a particular field. The reason because it gets a count that auto populates in a case number. But when it hits mindnight 12/31/2013 11:59:00 PM I want to autoincrement to start again from zero.

这是我的一些代码. 这段代码在Form1上,我从Form2上获取ID2的值,以仅当它们通过双击在Field1上命中时,保持大小写一致.

This is some code I have. This code is on Form1 and I get the value of the ID2 from Form2 to keep the case number consistant only when they hit at Field1 by using the Double Click

Private Sub Field1_DblClick(Cancel As Integer)
    Docmd.OpenForm "Form2",,,,acFormAdd,acHidden
    Me.Field1 = Format(Date, "YY") & "-" & Format(Forms!Form2!ID2, "0000")
    Me.Field2.SetFocus
End Sub

也许有人有不同的方法.用于向上计数. 现在,我遇到的问题是,当我到达"12/31/13 11:59:00 PM"时,我希望该自动增量将自身重置为1以开始一个全新的案件编号.使用提供的格式. 正确地知道,它们以YY-0001的格式(以13-0001案例编号示例为例)可以正常工作.我有以下代码,我认为它应可用于重置自动增量.可能有人对此有更好的方法. 我的代码.

Maybe someone has a different approach. For counting upwards. Now my problem I have is that when I reach "12/31/13 11:59:00 PM" I want that autoincrement to reset itself back to 1 to start a brand new case number. with the format provided. Right know it works fine the format they see is YY-0001 in order words 13-0001 case number example. I have the following code that I think It should work for reseting the autoincrement. probably someone has a better approach then this. My code.

Private Sub Field1_DblClick(Cancel As Integer)
    If Me.Text5 > "12:/31/2013 11:59:00 PM" Then
        DoCmd. DeleteObject acTable, "Table2"
        DoCmd.RunSQL "CREATE TABLE Table2 ([ID2] AUTOINCREMENT, [Field1] text (255))"
    end if

我要解决的问题是,如果他们不按数字,怎么改变呢?我如何迫使它改变. 我在计时器上有text5 计时器间隔每1000毫秒,即一秒 计时器运行的代码是

The problem I have how do I manage from changing what happens if they dont press the number how do I force it to change. I have the text5 on a timer timer intervals every 1000 milliseconds which is one second the code that runs for the timer is

Private Sub Form_Timer()
    Me.Text5 = Now()
End Sub

我有两个问题,如果他们永远不需要按我的验证方式会发生什么情况,以便它可以删除表并在工作后创建一个新表,自动递增将刷新唯一的问题是我将如何强制执行该操作自己做.

I have two problems what happends if they never need to press how do I validate so it can delete the table and create a new table once it works the autoincrement will refresh the only problem is that how do i force it that it will do it on its own.

推荐答案

尝试一下:

CurrentDb.Execute "ALTER TABLE YourTableNameHere ALTER COLUMN FieldNameHere COUNTER(1,1)"

这篇关于如何从Access数据库重置自动增量字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆