Question

I want to create sequence number in my order form that after save button it generate a Order No in Order No field of table, as I m not much knowledge in VBA but got from internet some codes which i try to implement but its not working The code is given below please see reply if there is any edit or where i m mistaked

Table: ID | date | party Name | Order No| Item | qty | Rate | Amount |

   Private Sub save_Click()

If Me.orderno = Null Then
Me.orderno = Nz(DMax([Order No], Order), 0) + 1

End If 


End Sub
Was it helpful?

Solution

If the name of the table is 'Order', the following should work:

If IsNull(Me.orderno) Then
    Me.orderno = Nz(DMax("[Order No]", "Order"), 0) + 1
End If

A few other comments:

The problems here were quite obvious, however, for future reference, you should state what error you are receiving and which line it occurs on. 'Not working' does not provide any clues.

Add the line DoCmd.RunCommand acCmdSaveRecord at the end, to insure that the record is saved. Make sure that the code is actually running and that orderno is bound to the field orderno. If it still doesn't appear to work, step through he code to see what is happening. As for the comment about autonumber, and autonumber is fine if you don't care about gaps in the numbering sequence, which will eventually occur using an autonumber.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top