Object variable not set

Hi all,

for the whole day, i have been tryin to locate an error which i reali have no idea abt.

The database, lets call it “stockinventory.nsf” have a view call “Formsend”. When i viewed the db in designer format, i found out that there is another view call “(Formsend)”

Ok the situation here is that in “Formsend”, i visually saw a document inside that view, but when i try to call it using the following, it juz keep pushing an error of “Object Variable not set”

code:

dim session as notessession

Dim db as Notesdatabase

dim view as notesview

dim doc as notesdocument

set db = session.getdatabase(“servername”,“stockinventory.nsf”,false)

set view = db.getView(“(Formsend)”)

set doc = view.getfirstdocument

======all is fine till this statement===========

Print doc.RequiredMgrField(0)

=========end===============

Now all of you might ask me to take .getView(“Formsend”) but the amazing part is when i tried using that, the error will be at view.getfirstdocument.

So i wonder if the view is empty so i input this code

if doc is nothing then

print “wahahaha”

end if

surprisingly the word wahahaha appear!!! And i am pretty sure the document exist in the view coz i actually saw it in the view!!! And in designer, i saw that document appear in the programmer pane for view (Formsend). Super weird rite?

I further tested using other databases beside stockinventory.nsf, all turn out fine. Haha is it a ghost database?

Can anyone solve the mystery of missing document? Plus, the error is fixed as “Object Variable not set” no other error msg come out.

Thanx

Regards,

hengshi

Subject: Object variable not set

  1. I’d suggest instead of getdatabase to use Dim db As NotesDatabase

Set db = New NotesDatabase( “Barcelona”, “plan.nsf” )

  1. if your agent is a scheduled agent, and if you try to open a database on another server, is the server running the agent a trusted server of the distant server ?

  2. if the agent is run locally on a notes client, has the signer of the agent rights on the distant database ?

  3. if there some reader fields in the document of the distant database ?

  4. i’ll suggest that you test the result of each line

set db = session.getdatabase(“servername”,“stockinventory.nsf”,false)

if db is nothing then

manage the error

end if

  1. i’ll suggest to asdd an error handling (on error goto) and to use the err statement to determine the cause of the error

see the example of the err function of the designer help

Public x As Single

Const TOO_SMALL = 1001, TOO_BIG = 1002

Sub GetNum

Dim Num As String

On Error GoTo Errhandle

Num$ = InputBox$(“Enter a value between 1 and 100:”)

x! = CSng(Num$) ’ Convert the string to a 4-byte single.

’ Check the validity of the entry.

If x! < 1 Then

  Error TOO_SMALL, "The number is too small or negative."

ElseIf x! > 100 Then

  Error TOO_BIG, "The number is too big."

End If

’ If the script gets here, the user made a valid entry.

MessageBox “Good job! " & Num$ & " is a valid entry.”

Exit Sub

’ The user did not make a valid entry.

’ Display the error number and error message.

Errhandle:

’ Use the Err function to return the error number and

’ the Error$ function to return the error message.

MessageBox “Error” & Str(Err) & ": " & Error$

Exit Sub

End Sub

GetNum ’ Call the GetNum sub.

Subject: RE: Object variable not set

Hi Ludovic Emo,

thanx for taking time off for my question.

  1. Tomorrow i will try out your suggestion.

2.3. My program doesn’t use an agent, at least i believe there is no agent running for that program itself.

  1. Hmm this bring me to a question. When i do the following:

set doc = view.getfirstdocument

Print doc.nameofField(0)

I observe that the field for that nameofField is “Names” and “Editable”. Is there anything wrong with that? Should be no right?

  1. Actually for the whole of today, I had try to print a simple statement after each and every line of the code- I know i can use debugger but i preferred this stupid method, and found out that the view might not have contained the document by the if statement.

I try this too…Print db.isOpen. The result return true. Which brought me to wonder if the doc actually got anything inside. That is why i used the if statement.

I still quite amazed by the existence of document yet unretrievable hahaha

Regards,

hengshi

Subject: RE: Object variable not set

Add ‘new’ to instantiate the session as follows and see if you still get the error message:

dim session as new notessession ----> (added ‘new’ here)

Dim db as Notesdatabase

dim view as notesview

dim doc as notesdocument

set db = session.getdatabase(“servername”,“stockinventory.nsf”,false)

set view = db.getView(“(Formsend)”) —> (If “(Formsend)” & “Formsend” with and without brackets are two different views, then there is no problem. If both are exactly with same name including brackets, then use alias of that view in the code)

set doc = view.getfirstdocument

Print doc.RequiredMgrField(0) —> should print the content. If it is a multivalue field, it prints only the first value of that array. If single value field, it prints the name in it.

Hope this helps.

Subject: Object variable not set

Hi Hengshi,

Firstly I think you will find that the app is confusing the two views. Use an alias on the views, or change there name to ensure the views are trully individual. The use of () is just there to make the views invisable.

As for the Object Variable not set, if there is no document found in the view, then the doc is still “Nothing” and as a consiquence the Object Variable is not set.

Hope this helps

Jeremy

Subject: RE: Object variable not set

Hey Jeremy,

Thanx for ur time on my question, so you suggesting i call for the view using another alias?

And as for missing document, I and my friend both really did observe the document in the view itself. So is there an explanation for that?

Hope my question isn’t a stupid one

Regards,

hengshi

Subject: Object variable not set

If the code is exactly as you have pasted then you haven’t instantiated the session object using the New method so the object variable not set is thrown when you use session.GetDatabase()

If you spent all day looking then can I suggest error handling? Seriously it will save you a lot of time. If you go to openntf.org there is a great template that you can download for free called OpenLog. It is well worth doing.

If you already knew all that then I apologise.

HTH, Rob.

Subject: RE: Object variable not set

Hi Rob,

Its alright with me, so no apologize needed. I had considered using errorhandling but then the problem now is I can’t get the document which seems to exist visually but not physically. Haha sounds absurb right?

Anyway today I hope i can based on the others suggestions and try it out on the ghosty program to see if i can solve the mystery.

Oh yes by the way, mistyped…should have been

Dim session as new notessession

my fault on this part.

Thanx everyone

Regards,

Hengshi