Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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
VB
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
Posted
Updated 12-Oct-12 5:20am
v3
Comments
ZurdoDev 10-Oct-12 8:17am    
But it looks like you are pulling the receipt_no from a textbox, not an autoincrement?
[no name] 12-Oct-12 11:44am    
*IF* you have an auto increment field in your database and *IF* it is not working correctly, you are looking in the wrong place. You should be looking at your database to see why the auto increment field is not behaving.

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:
SQL
SELECT (investigation ) As Investigations FROM investigation
Can return records in any order Access feels like, which may not be the one you expect.
SQL
SELECT (investigation ) As Investigations FROM investigation ORDER BY investigation ASC
Fixes that.
 
Share this answer
 
Comments
sarfarazbhat 14-Oct-12 12:49pm    
I tried order by but no success.any other idea sir
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900