Null error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a custom entry form that keeps producing a error saying that the index
can not be null. The index is assigned to an autonumber field and during
processing of the form the autonumber field doesn't have a value until the
record gets saved. Is there a way to have the autonumber field generate an
index prior to updating so that I no longer get the error saying that the
index is null?
 
When you say it's an Autonumber field, do you mean the built-in Autonumber
data type, or is it a "roll-your-own" version of Autonumber?

The built-in Access Autonumber value is generated when you first "touch" the
row, before you save it, so I don't see how you could possibly be getting a
Null-related error related to it.
 
This is the code I have for the click event that is giving me trouble.

Private Sub MoveToAttendees_Click()
On Error GoTo MoveToAttendeesError

Dim MyDB As Database
Dim MyStudents As Recordset
Dim MySessions As Recordset
Dim I, X As Integer
Dim MyCriteria As String

Set MyDB = CurrentDb
Set MyStudents = MyDB.OpenRecordset("SessionAttendance")

DoCmd.Hourglass True

For I = 0 To Me.EmployeesList.ListCount
'MsgBox "on item # " & I
If Me!EmployeesList.Selected(I) = True Then
With MyStudents
.AddNew
!CourseID = Me.CourseID
!SessionID = Me.SessionID
!EmpID = Me.EmployeesList.ItemData(I)
!Attended = True
.Update
End With
End If
Next I

MyStudents.Close
MyDB.Close
Set MyDB = Nothing
Form.Refresh
DoCmd.Hourglass False
Me.MoveToAttendees.DefaultValue = False

DisplayEmailButton

Exit Sub

MoveToAttendeesError:
If err.Number = 3022 Then 'Duplicate record
MsgBox "The employee '" & Me!EmployeesList.Column(2, I) & " " &
Me!EmployeesList.Column(1, I) & _
"' is already attending this session."
Else
MsgBox Error$ & err.Number
End If

MyStudents.Close
MyDB.Close
Set MyDB = Nothing
DoCmd.Hourglass False
Me.MoveToAttendees.DefaultValue = False
End Sub

Where it calls the sessionID it pulls a null value from the SessionID
textbox which is a autonumber field in the table. So I need a way for that
textbox to actually have a value in it. It isn't filling the value.
 
Back
Top