Sorry about the jargon, Maria. I didn't know how much you knew.
Use a form to input your data, not a table.
Open the form in Design View.
Right Click on the Check Number control (text box)
Go to Properties
Click on the Event tab
Click next to AfterUpdate, choose Event Procedure, click just right of that
and open up a code page.
Just above where it says
End Sub
put the code
Dim LastNum as Long
LastNum = NZ(DMax("[Check Number]","TblOfCheckNumbers"),0)
If Me.[Check Number] > LastNum + 1 Then
Me.[Check Number].Undo
MsgBox "That was not the next check number. The previous check number was "
& LastNum
End If
Replace TblOfCheckNumbers with the real name of the table that contains the
check number.
I'm assuming above that you don't want the code to automatically fill in the
next check number but if you do, open an 'After Update' code page for a
different control in your form, one you always fill in when you are entering
a new record (perhaps the date?) and enter:
Dim LastNum as Long
LastNum = NZ(DMax("[Check Number]","TblOfCheckNumbers"),0) + 1
If Me.[Check Number] =LastNum
End If
Put things in the After Update event of a control means that when you have
finished entering something into a text box, or choosing something with a
combo box, your code will happen.
One problem you will have though, if you really do have a field in your
table called Date, then before you do much else, you really ought to rename
it.
Look up Access Reserved Words field names to find out what may happen if you
don't. Call it XDate or anything else (and be prepared to spend time mending
queries, reports and forms)
You can always change labels in forms and reports to say Date so long as the
field doesn't
Evi
> Thank you for your response (I apologize for the delay this is my first time
> using this service and I was having some problems in getting through).
[quoted text clipped - 44 lines]
> > > name" or in the "data type" to ensure that the check number entered is in
> > > numerical order if is not, the system is to reject it (like a control).
Maria (MAC) - 19 May 2008 16:08 GMT
Thank you so much for answering and for explaining it
> Sorry about the jargon, Maria. I didn't know how much you knew.
>
[quoted text clipped - 112 lines]
> > > > numerical order if is not, the system is to reject it (like a
> control).
Maria (MAC) - 20 May 2008 00:01 GMT
Evi, I did the steps that you indicated below but I am getting the following
error Message:
THI IS MY INPUT:
Private Sub Check_No_AfterUpdate()
Dim LastNum As Long
LastNum = Nz(DMax("[Check_No]", "Loan Check Log - 2008"), 0)
If Me.[Check_No] = LastNum + 1 Then
Me.[Check_No].Undo
MsgBox "That was not the next check number. The previous check number was "
& LastNum
End Sub
When I enter "End If" - I get "Block Error - Expected End Sub"
So when I change it to "End Sub" - I get "Compile Error - Block If withough
End If"
and both times the first line "Private Sub Check ..." is highlighted in
yellow
> Sorry about the jargon, Maria. I didn't know how much you knew.
>
[quoted text clipped - 112 lines]
> > > > numerical order if is not, the system is to reject it (like a
> control).
Evi - 20 May 2008 13:55 GMT
Hi Maria
Put the End If just after the MsgBox line so that it now says
Dim LastNum As Long
LastNum = Nz(DMax("[Check_No]", "Loan Check Log - 2008"), 0)
If Me.[Check_No] = LastNum + 1 Then
Me.[Check_No].Undo
MsgBox "That was not the next check number. The previous check number
was " & LastNum
End if
End Sub
Evi
> Evi, I did the steps that you indicated below but I am getting the following
> error Message:
[quoted text clipped - 133 lines]
> > > > > numerical order if is not, the system is to reject it (like a
> > control).