VB Code help please

hcoburn

Novice
Local time
Today, 13:24
Joined
Feb 3, 2008
Messages
5
I have been passed a very simple database with one table and one form. It is being used simply as an invoice number generator. I have been asked to empty the database for use on a new site and prefix the primary number with a letter to distinguish it from the previous site.

The form has two fields - one for a customer number and one for a case number, and then a button which runs a VB command to add the customer number and case number to a new record in the table, and display that primary record number.

I have put a format against the primary key in the table to display an 'F' and 5 digits, but the form where the number is generated won't display this format. I'm not at all good with VB code and I can't pick out where the problem may be - would someone mind having a look at it please?

Many Thanks, Hazel.

Private Sub GoNewNumber_Click()
Dim NextNumber As Long
Dim MyDb As DAO.Database
Dim MyRs As DAO.Recordset
Set MyDb = CurrentDb
Set MyRs = MyDb.OpenRecordset("BillNumbers")
If IsNull(Me![Client Number]) Or Me![Client Number] = 0 Then
MsgBox "Client Number cannot be blank or Zero"
Exit Sub
ElseIf IsNull(Me![Matter Number]) Or Me![Matter Number] = 0 Then
MsgBox "Matter Number cannot be blank or Zero"
Exit Sub
End If
NextNumber = DMax("[BillNumber]", "BillNumbers") + 1
Me!NewNumber = NextNumber
Me!ClientNumber = Me![Client Number]
With MyRs
.AddNew
!BillNumber = NextNumber
!ClientNumber = Me![Client Number]
!Matternumber = Me![Matter Number]
.Update
End With
Me!NewNumber.SetFocus

End Sub
 

Users who are viewing this thread

Back
Top Bottom