Object variable not set

Dear AllI have a database developed in R5.

I wrote the lotus script in one of the field (sub initialize) in the form.

The script as below

Sub Initialize

Dim ws as new notesuiworkspace

Dim uidoc as notesuidocument

Dim doc as notesdocument

set uidoc = ws.currendocument

set doc = uidoc.document

doc.field1 = “test1”

doc.field2 = “test2”

End Sub

It is fine runing in R5

When I move this db to R6 server and using client 6.0.1 in Window XP and test, it give me the error “Object variable not set” in the “set doc = uidoc.document” line.

Has any one face this problem before or know how to solve…Please help

Thank you

from Nyan

Subject: Object variable not set

This problem has discussed a few times before in this forum.The only solution seems to be to move the code to another event like the PostOpen-event of the form, where you can use the Source-parameter instead of creating a new NotesUIWorkspace …

Subject: Object variable not set

Add the extra Dim.

Sub Initialize

Dim ws As New notesuiworkspace

Dim uidoc As notesuidocument

Dim doc As notesdocument

Dim field1, field2 As String	



Set uidoc = ws.currentdocument

Set doc = uidoc.document



doc.field1 = "test1"

doc.field2 = "test2"

End Sub

Or use some arrays.

Sub Initialize

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document



field1 = doc.field1

field1(0) = "test1"

doc.field1 = field1



field2 = doc.field2

field2(0) = "test2"

doc.field2 = field2	

End Sub

Subject: RE: Object variable not set

two remarks:

Dim field1, field2 As String.
with this line you declare fields1 as a Variant and field2 as a String.

doc.field1 = “test1”
this line of code is perfectly OK, and declaring the variable ‘field1’ as a string, has nothing to do with this, nor do you have to use arrays : doc.field(0)=“test1” is allowed but not nescessary. It is only nescessary the other way round : MyString$=doc.field(0)