vb6中Access 2007中的增量字段 [英] Increment field in access 2007 from vb6
问题描述
亲爱的朋友.
我是萨法拉兹(Sarfaraz).我已经完成了我的项目,并将其安装在目标计算机上.他们发现了一个问题.
问题是我在Access 2007表中有一个名为RECEIPT_NO的字段,该字段是自动递增的(在将前一个递增1后生成下一个receive_no).问题在于,在数据库中保存32条记录后,自动增量字段会冻结为32或27,并且此后不会更改.
代码如下
在form_Load上,我有
Dear friends.
I am Sarfaraz. I have completed my project and after installing it on target computer. They have found a problem in it.
The problem is that i have a field in access 2007 table called RECEIPT_NO which is auto increment( generates the next receipt_no after incrementing the previous with 1). The problem is that after saving 32 records in the database the auto increment field freezes to 32 or 27 and does not change after that.
The code is as under
ON the form_Load i have
Private Sub Form_Load()
If rs.BOF = True Then
MsgBox " There are no Records in the database", vbInformation, "No records in Database"
Text1.Text = 1' displays receipt_No
Label6.Caption = Date
List1.Clear
Con.Close
Connection
sql = "SELECT (investigation ) As Investigations FROM investigation"
Set rs = New ADODB.Recordset
rs.Open sql, Con, adOpenDynamic, adLockOptimistic
Do While Not rs.EOF
List1.AddItem UCase(rs!Investigations)
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
Exit Sub
Else
rs.MoveLast
Text1.Text = rs.Fields(0) + 1
Label6.Caption = Date
List1.Clear
Connection
sql = "SELECT (investigation ) As Investigations FROM investigation"
Set rs = New ADODB.Recordset
rs.Open sql, Con, adOpenDynamic, adLockOptimistic
Do While Not rs.EOF
List1.AddItem UCase(rs!Investigations)
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
End If
End Sub
请帮助我解决此问题.
谢谢
Please help me in solving this problem.
Thank you
推荐答案
我们不能真正回答这个问题,只能给您一些一般性的想法.
发生这种情况的原因有很多-您确实需要使用调试器仔细查看,并尝试复制程序运行的条件.例如,数据库是作为单用户还是多用户使用?
但是,要看的一件事是,如果您正在使用数据库中的最后一个数字来表示下一个mnumber,那么在撤消它们时需要在tehrecords上指定排序顺序-否则无法保证它们是按您想要的顺序返回:
We can''t really answer this exactly, only give you some general ideas to play with.
There are a huge number of reasons why this might be happening - you really need to look more closely using the debugger, and also try to replicate the condition under which the program is running. For example, is the database being used as single user, or multiuser?
However, one thing to look at is that if you are using the last number in the database to indicate what the next mnumber will be, you need to specify the sort order on tehrecords when you retirve them - otherwise there is no guarantee that they are returned in the order you want:
SELECT (investigation ) As Investigations FROM investigation
可以以Access感觉到的任何顺序返回记录,这可能不是您期望的.
Can return records in any order Access feels like, which may not be the one you expect.
SELECT (investigation ) As Investigations FROM investigation ORDER BY investigation ASC
解决了这个问题.
我通过从表格中选择max(receipt_no)解决了这个问题.
sql =从患者中选择max(Receipt_No)"
无论如何,我感谢所有提出了很多方法并最终帮助我解决问题的成员.
谢谢
I solve the problem by selecting the max(receipt_no) from table.
sql = "select max(Receipt_No)from patients"
Anyways, I thank all the members who suggested so many ways and finally help me to solve my problem.
Thank you
这篇关于vb6中Access 2007中的增量字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!