Autogenerating study ID number (1 Viewer)

UCLA Lorna

Registered User.
Local time
Yesterday, 20:55
Joined
Mar 8, 2005
Messages
32
I've got some code to create a unique ID number for each patient that enters my research study. It's just in sequential order with an 'S' in front such that the 1st patient is S001 and the 2nd is S002. I first create the sequential number and then add the S to it, but I'm getting the following error:


Run-time error '2115'

The macro or function set the to BeforeUpdate or ValidationRule property for this field is preventing Microsoft Access from saving the data in the field.



There are no validation rules or BeforeUpdate properties for this field. Here is the SQL code that I used:


Private Sub SCounter_LostFocus()
Me.SID.SetFocus
If Not IsNull(Me.SCounter) Then
Me.SID.Value = "S" & Me.SCounter.Value
End If
End Sub

Private Sub DateReg_AfterUpdate()
Me.SYearBase.Value = "07"
End Sub

Private Sub Interviewer_AfterUpdate()
Dim db As DAO.Database
Dim rst As DAO.Recordset

'Creating consecutive ID numbers using a counter
If IsNull(Me.DateReg) Then
numtimes2 = numtimes2 + 1
If numtimes2 > 1 Then
MsgBox "Call Date Must Be Entered"
SCounter_LostFocus
Me.DateReg.SetFocus
End If

Else
If IsNull(Me.SCounter) And Not IsNull(Me.DateReg) Then
Set db = CurrentDb()
Set rst = db.OpenRecordset("select * from MainTable where syearbase='" & Me.SYearBase & "' order by scounter desc")

With rst
Me.SCounter.SetFocus
If .EOF Then
Me.SCounter.Text = "001"
Else
Me.SCounter.Text = Format(CStr(CInt(!SCounter) + 1), "000")
End If
End With

ElseIf IsNull(Me.DateReg) Then
'probably exiting so don't calculate anything'
End If
End If

Me.SID.Value = "S" & Me.SCounter.Value
End Sub



The error occurs after I enter the 'Interviewer' field. The 'SCounter' field is generated correctly, but then I get the error message. If I click on 'End', the cursor moves to the 'SID' field and if I tab again, the ID generates correctly. What's wrong with my code that causes the 1st error?

Thanks.
 

missinglinq

AWF VIP
Local time
Yesterday, 23:55
Joined
Jun 20, 2003
Messages
6,423
"The error occurs after I enter the 'Interviewer' field."

If this is correct, then the problem is not being caused by something in the Interviewer_AfterUpdate event, but rather by something in its OnEnter or GotFocus event or possibly, as Access says, in its BeforUpdate event. It could even be generated by something that occurs when you leave the previous control on your way to enter Interviewer.

We probably need to see your Inteviewer_BeforeUpdate code.
 

Users who are viewing this thread

Top Bottom