Object variable not set

I am getting this error message: “Object Variable not set” for this snippet of code below: Set Trooper=TrooperInfo.GetDocumentByKey(Fulltrim(TString(1)). I have my view TrooperInfo sorted and thought I initialized everything properly at the beginning of my coding, does anyone see what I did wrong?

Sub Click(Source As Button)

'// 'Declare a new session varialbe

Dim session As New NotesSession

Dim db As notesdatabase

Dim ActivityInfo As notesview

Dim TrooperInfo As notesview

Dim Trooper As notesdocument

Dim FieldArray As Variant

Dim TString(0 To 106) As String

Dim pos As Integer

Dim LenOf As Long

Dim RecLen As Integer

Dim NumRec As Long

Dim CarrPhn As String

Dim CarrFax As String

Dim TempDate As notesdatetime

Dim eDate As notesdatetime

'// 'Set dataFileName$, which will be the name of the file to open, equal to the user input

dataFileName$ = "C:\Tars7.txt"

'// 'Set db equal to current database; numDocs& initialized to 0;fileNum% initialized;

Set db = session.CurrentDatabase

Set ActivityInfo = db.GetView("ActivityInfo")

Set TrooperInfo = db.GetView("TrooperInfo")



numDocs& = 0

fileNum% = Freefile()

'// 'Open the file that the user specified for input

Open dataFileName$ For Input As fileNum%

LenOf = Lof(fileNum%)

RecLen = 404

NumRec = Clng(LenOf / RecLen)

'// 'While not end of file, loop through the following

'// 'There are no comments in loop because it slows processing

Print "Progress: 0%"

Do While Not Eof( fileNum% )

	Line Input #1, textLine$ 

	

	textLine$ = Fulltrim(textLine$)

	For k = 0 To 106

		pos = Instr(textLine$,",")

		length = Len(textLine$)

		TString(k) = Mid(textLine$,1,pos - 1)

		textLine$ = Right(textLine$,length - pos)

	Next

	

	Set Activity = ActivityInfo.GetDocumentByKey(TString(0))

	If Not Activity Is Nothing Then

		Goto FinishedDocument

	End If

	Set Activity = New NotesDocument( db )

	

	'//	'Change TString(0) into date type for InspDate

	Call Activity.ReplaceItemValue("Form","Activity")

	'Call Activity.ReplaceItemValue("UNID",Acitivity.UniversalID)

	Set TempDate = New notesdatetime(Fulltrim(TString(0)))

	Call Activity.ReplaceItemValue("InspDate",TempDate)

	Call Activity.ReplaceItemValue( "TrprNum", Fulltrim(TString(1)))

	'Check for valid trooper number

	Set Trooper = TrooperInfo.GetDocumentByKey(Fulltrim(TString(1)))

	If(Trooper Is Nothing) Then

		If(Instr(1, FailureStr2, TString(1), 1) = 0) Then

			FailureStr2 = FailureStr2 + TString(1) + Chr(13)

		End If

	Else

		Call Activity.ReplaceItemValue("TrprLName", Trooper.LastName(1))

		Call Activity.ReplaceItemValue("TrprFName", Trooper.FirstName(1))

		Call Activity.ReplaceItemValue("Rank", Trooper.Rank(1))

	End If

Thank you

Subject: Verify your view object is NOT nothing…

Don’t assume that your set view statement is successful. You should test to see if its not nothing:

if TrouperInfo is Nothing then

’ the view object wasn’t set to the var.

else

’ its a good view

end if

or if the logic seems backwards to you,use:

"if Not TrouperInfo is Nothing then "

Hope that helps

Subject: RE: Verify your view object is NOT nothing…

I can’t test that code because I cant get passed the line of code immediately before it.

Subject: RE: Verify your view object is NOT nothing…

ok, i see what i did, i initialized my view incorrectly at the beginning of my coding. I had a space in between Trooper and info.