Problem with Counter Settings!

A

a24t42

I am having a problem adapting the custom counter for multi user. Here
is what I have -

1. A form named Regulators. I have set the following
a. On Load - I disable the Mouse wheel
b. BeforeUpdate - I have the following script -

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then Me!Code = "SREG"
' Start of BeforeUpdate event for the form
If Me![ID] = "" Then
' only want to do this if it's an empty codenumber
Dim db As Database, rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("CounterTable") ' replace this with the name
of the "next numbers" table
rs.FindFirst "[ID] = " & "'" & Me![IDText] & "'"
' since it's text, we've wrapped it in single quotes
If Not rs.NoMatch Then
' Match found, all OK
Me![ID] = rs![NextNumber]
rs.Edit
rs![NextNumber] = rs![NextNumber] + 1
rs.Update
Else
' no match was found, need to display the error and cancel the updat
Cancel = True
End If ' End of NoMatch check
End If ' End of [CodeNumber]="" check
End Sub

2. On the form, I have the following controls -
a. ID - number, Long, Primary Key. Control Source ="SREG" &
Format(Nz(DLookUp("[NextAvailableCounter]","CounterTable"),1),"0000")

b. Code - Text, 4

Here is what I am trying to do - OnLoad I want to disable the mouse
wheel and set
Code:
 ="SREG". I also want to look up the
[NextAvailableCounter] in the table CounterTable.

My problem is that I keep getting the error  - "Index or primary key
can not contain have a null value."

I must not have something set correctly. My knowledge of VB is
minimal. Any help would be appreciated. Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top