Page 1 of 1

[Solved] Object variable not set error message

Posted: Thu Feb 24, 2011 7:27 am
by nicari
The following code snipped is taken from a basic documentation:

Code: Select all

	dim databaseContext as object
	dim dataSource as object
	dim queryDefinitions as object
	dim queryDefinition as object
	dim statement as object
	dim resultSet as object 
	dim I as integer
		
	    databaseContext = createUnoService("com.sun.star.sdb.databaseContext")
	    dataSource = databaseContext.getByName("Customers")
	    queryDefinitions = dataSource.getQueryDefinitions()

	    for I = 0 to queryDefinitions.count()-1
	    	queryDefinition = queryDefinitions(I)
	    	msgbox queryDefinition.name
	    next I
looks very straightforward, but running this code always throws an exception :
"BASIC runtime error: Object variable not set" at the line
dataSource = databaseContext.getByName("Customers").

What did I wrong here? Or is it the result of a bug? Is there a way to work
around by formulation the code differently?

Any helpful suggestion would be highly appreciated.
Thanks in anticipation.

Title Edited. A descriptive title for posts helps others who are searching for solutions and increases the chances of a reply. BBCode fixed also (Hagar, Moderator).

Re: Please help by checking for syntax error

Posted: Thu Feb 24, 2011 8:41 am
by B Marcelly
Hi,
Forum tip : click button code before and after your code.

Here is the corrected instruction:

Code: Select all

databaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
The difference is the case of letter D in DatabaseContext.
All strings used in OOo programming are case-sensitive.

Re: Object variable not set error message

Posted: Fri Feb 25, 2011 8:56 am
by nicari
Thanks very much, Bernhard
I corrected the spelling as you recommended.
But the subsequent line still makes trouble:

Code: Select all

 dataSource = databaseContext.getByName("musik")
However the error message has now changed. It reads now:
BASIC runtime error:
An exception occurred
Type: com.sun.star.container.NoSuchElementException
message: musik

I don't know what to make out of this message and would
appreciate your comment.
It may be necessary to give some information about my system:
External data storage mySQL with several databases (schemas) on a LAN
server, connected by TCP/IP. Both server and clients are running
PCLinuxOS as operation systems.

Thanks for changing the title of this post. it's much more descriptive.
Egbert

Re: Object variable not set error message

Posted: Fri Feb 25, 2011 9:35 am
by B Marcelly
Hi,
Your database must be registered.
Menu Tools > Options > OpenOffice.org Base > Databases
Then you must use the registered name in this instruction.

Re: Object variable not set error message

Posted: Fri Feb 25, 2011 11:38 am
by nicari
Thanks,
Now it works fine
Egbert