Run-time error 94: Invalid Use of Null (1 Viewer)

rbchoi

New member
Local time
Yesterday, 16:20
Joined
Sep 20, 2009
Messages
3
Hi, every time I try to open a form that is linked to another form, I get the "run-time error 94: invalid use of null" message. Below is the code that pops up when I click "debug". Can anyone figure out why I keep getting this message and how I can fix it? Much thanks!

-----------------------------------------------

Private Sub Form_Load()

Me.OrderBy = "[ID] ASC"
Me.OrderByOn = True

Dim rst As Object
Dim rCount As Integer
Set rst = Me.RecordsetClone
On Error Resume Next
rst.MoveLast
On Error GoTo 0
rCount = rst.recordCount

Dim SName As String
Dim SSurname As String

SName = DLookup("SName", "Students", "SSN='" & StudentId & "'")
SSurname = DLookup("SSurName", "Students", "SSN='" & StudentId & "'")

lblNumEntry.Caption = "Student " & SName & " " & SSurname & " has " & rCount & " Intake records"

DoCmd.GoToRecord , , acLast

If rCount = 1 Then
btnNext.Enabled = False
btnPrevious.Enabled = False
Else
btnNext.Enabled = False
btnPrevious.Enabled = True

End If
End Sub
 

ajetrumpet

Banned
Local time
Yesterday, 18:20
Joined
Jun 22, 2007
Messages
5,638
something is being set to NULL, or there is a null check where there it doesn't it. give us the highlighted line instead of the whole thing
 

rbchoi

New member
Local time
Yesterday, 16:20
Joined
Sep 20, 2009
Messages
3
The highlighted line is:

SName = DLookup("SName", "Students", "SSN='" & StudentId & "'")
 

rbchoi

New member
Local time
Yesterday, 16:20
Joined
Sep 20, 2009
Messages
3
I'm not exactly sure what you mean by "set" and "defined" -- however, here is the code for launching the Student Intake form from the Student form. I want to link the records by matching the SSN (in the Student form) and the StudentId (in the Student Intake form).

------------------------------------------------------

Private Sub btnIntake_Click()

On Error GoTo Err_btnIntake_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim stDocName As String
Dim stLinkCriteria As String

Dim recordCnt As Integer

recordCnt = DLookup("Count(*)", "StudentIntakeForm", "StudentId = '" & SSN & "'")

If (recordCnt > 0) Then
stDocName = "Student Intake Form"

stLinkCriteria = "[StudentId]=" & "'" & Me![SSN] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria

With Forms(stDocName)
.DateIntake.SetFocus
.StudentId.Enabled = False
.btnCancelEdit.Visible = True
.btnCancelInsert.Visible = False
.btnInsertNew.Enabled = True
.btnDelete.Enabled = True
End With
Else

Dim YearlyIncomeId As Integer
Dim ProgramId As Integer

YearlyIncomeId = DLookup("Min(ID)", "HouseholdIncome")
ProgramId = DLookup("Min(ID)", "Programs")

Dim myQ As String
myQ = "INSERT INTO StudentIntakeForm (StudentId, ProgramId, YearlyIncomeId) Values ('" + SSN + "'," & ProgramId & "," & YearlyIncomeId & ")"

DoCmd.SetWarnings False
DoCmd.RunSQL myQ
DoCmd.SetWarnings True

stDocName = "Student Intake Form"

stLinkCriteria = "[StudentId]=" & "'" & Me![SSN] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria

With Forms(stDocName)
.DateIntake.SetFocus
.StudentId.Enabled = False
.btnCancelEdit.Visible = False
.btnCancelInsert.Visible = True
.btnInsertNew.Enabled = False
.btnDelete.Enabled = False
End With
End If

Exit_btnIntake_Click:
Exit Sub

Err_btnIntake_Click:
MsgBox Err.Description
Resume Exit_btnIntake_Click

End Sub
 

ajetrumpet

Banned
Local time
Yesterday, 18:20
Joined
Jun 22, 2007
Messages
5,638
The highlighted line is:

SName = DLookup("SName", "Students", "SSN='" & StudentId & "'")

my guesses are:

1) studentID is not a string
2) the lookup is resulting in NULL
3) other code is interfering up until this point, and the highlighted line is the consequence of what's already been bugged at a prvious point in timel
 

Users who are viewing this thread

Top Bottom