[Solved] Object variable not set error message

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
nicari
Posts: 27
Joined: Mon Jan 03, 2011 3:14 am

[Solved] Object variable not set error message

Post 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).
Last edited by nicari on Fri Feb 25, 2011 11:39 am, edited 1 time in total.
ooo-build 3.2.1.4 on PCLinusOS 2010
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Please help by checking for syntax error

Post 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.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
nicari
Posts: 27
Joined: Mon Jan 03, 2011 3:14 am

Re: Object variable not set error message

Post 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
ooo-build 3.2.1.4 on PCLinusOS 2010
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Object variable not set error message

Post 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.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
nicari
Posts: 27
Joined: Mon Jan 03, 2011 3:14 am

Re: Object variable not set error message

Post by nicari »

Thanks,
Now it works fine
Egbert
ooo-build 3.2.1.4 on PCLinusOS 2010
Post Reply