|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Autoincrement field
Hello Iwells (Merry Christmas first of all) I again thank you for your preciouse help
concerning the availability matter. I have a function that autonumbers my invoice field in my invoice table. To explain things better the IDInvoice (sorry I have italian terms on my table) is taken care of the access Auto Number field while I have this function that is called any time I click on the NewInvoice cmdButton for it in order to get a new invoice number. Thing is I want to prevent as much as possible any duplication of the invoices so I have button that freezes the field in my form as well as a control that I am trying to develop that checks if there is already a number ... And .... Guess what ...doesn' work here is what i am working on: Private Sub cmdNuovafattura_Click() ' click here and I get a new Invoice number: it works Me![strNumFatt] = NuovaFattura() Me![curImporto].SetFocus ' move the focus over the money field Me![cmdNuovafattura].Enabled = False End Sub Public Function NuovaFattura() As Long If Me![strNumFatt] < 1 Then 'Find highest NumeFattura in the tblDettFatture table and add 1 Aggiungi = DMax("[strNumFatt]", "tblfatture") + 1 'Assign function the value of the NuovoNum NuovaFattura = Aggiungi Exit Function ElseIf Me![strNumFatt] >= 1 Then MsgBox " You ahve already a number for this invoice " End If End Function I want to have full control over the number of the invoices |
|
#2
|
|||
|
|||
|
Hi ItalianLodging
Just a couple of things here first. 1) Your variable Aggiungi wasn't declared or at least not in your post. That will have to be corrected. 2) You are only checking to see if an invoice number is less than 1 and if true, will generate a new number based on the max number + 1. I am assuming that you want to generate a new invoice number if it is a new record otherwise display a message that an invoice number already exists. So to simplify your code you might just write it this way. Private Sub cmdNuovafattura_Click() If Not IsNull(strNumFatt) Then MsgBox " You have already a number for this invoice " Else strNumFatt.Value = DMax("[strNumFatt]", "tblfatture") + 1 End If Me![curImporto].SetFocus Me![cmdNuovafattura].Enabled = False End Sub This will display a message box if a number already exists. If the invoice number is Null, it will create a new invoice number one higher than the highest number in your table. Just set the properties to the field strNumFatt to No Duplicates and the default value as Null (Blank) The code you have already written should work after you have declared your variable or use the sample one I made here. Merry Christmas, lwells |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Autoincrement field |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|