UCLA Lorna
Registered User.
- Local time
- Today, 07:57
- 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.
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.