antonyx
Arsenal Supporter
- Local time
- Today, 16:47
- Joined
- Jan 7, 2005
- Messages
- 556
hello all..
i was told when trying to create this invoice number.. why not just increment? why are you using random number?
the reason i wanted it random is because that is what my user wanted.. now they say they would prefer to have an incremented number..
here is what i am using now..
this creates a random 5 digit number.. and then uses the 'accountref' to create a number..
here are some example numbers
Q8A12765
KYP89008
MCD34445
now.. instead of this random number.. my client wants the following..
the first ever invoice created will be
Q8A10001
account ref
number
what i want to do is when the number is created.. the form looks up the previous value in the invoice table..
so if i create another invoice it will become
Q8A10002
if i then delete the 02 invoice.. and create another invoice for a different account holder.. it should be
MCD10002
so basically it always checks the last invoice and increments 1 number.. regardless of the accountref before it..
struggling at the moment.. any help is much appreciated.
i have this other code that uses a similar method using the date..
eg first ref would be (for a record in january 2007)
01070001, and then a second on the same day would be 01070002, then a record for february 2007 would be 02070001 etc.. im sure the clue to what i want for the invoice is in this snippet but i cant get it working..
here is that code..
i was told when trying to create this invoice number.. why not just increment? why are you using random number?
the reason i wanted it random is because that is what my user wanted.. now they say they would prefer to have an incremented number..
here is what i am using now..
Code:
Private Sub btnGenerate_Click()
Dim rdm As Long
Dim xlook As Variant
If IsNull(cboaccountref) Then
Me.cboaccountref.SetFocus
Else
Do
rdm = Int((99999 - 11111 + 1) * Rnd + 11111)
Me.txtinvoicenotest = Me.cboaccountref & rdm
xlook = DLookup("[InvoiceRef]", "tblInvoice", "[InvoiceRef] = '" & Forms!frmNewInvoice!txtinvoicenotest & "'")
Loop Until IsNull(xlook)
Me.txtInvoiceNo = Me.txtinvoicenotest
DoCmd.RunCommand acCmdSaveRecord
DoCmd.close
End If
End Sub
this creates a random 5 digit number.. and then uses the 'accountref' to create a number..
here are some example numbers
Q8A12765
KYP89008
MCD34445
now.. instead of this random number.. my client wants the following..
the first ever invoice created will be
Q8A10001
account ref
number
what i want to do is when the number is created.. the form looks up the previous value in the invoice table..
so if i create another invoice it will become
Q8A10002
if i then delete the 02 invoice.. and create another invoice for a different account holder.. it should be
MCD10002
so basically it always checks the last invoice and increments 1 number.. regardless of the accountref before it..
struggling at the moment.. any help is much appreciated.
i have this other code that uses a similar method using the date..
eg first ref would be (for a record in january 2007)
01070001, and then a second on the same day would be 01070002, then a record for february 2007 would be 02070001 etc.. im sure the clue to what i want for the invoice is in this snippet but i cant get it working..
here is that code..
Code:
Private Sub txtjobdate_LostFocus()
Dim maxRef As Variant, maxID As Integer
Dim codeDate As String, maxDate As String
codeDate = Format(txtjobdate, "MMYY")
maxRef = DMax("JobRef", "tblJob", "JobRef like '" & codeDate & "*'")
If (IsNull(maxRef)) Then 'test for new month
maxID = 0 'reset id to 0
Else
maxDate = Left(maxRef, 4) 'get date code
maxID = CInt(Right(maxRef, 4)) 'convert to int
End If
Me.txtjobref = codeDate & Format(maxID + 1, "0000")
End Sub