[Solved] Object variable not set error message

Creating a macro - Writing a Script - Using the API

[Solved] Object variable not set error message

Postby nicari » Thu Feb 24, 2011 7:27 am

The following code snipped is taken from a basic documentation:

Code: Select all   Expand viewCollapse view
   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
nicari
 
Posts: 27
Joined: Mon Jan 03, 2011 3:14 am

Re: Please help by checking for syntax error

Postby B Marcelly » Thu Feb 24, 2011 8:41 am

Hi,
Forum tip : click button code before and after your code.

Here is the corrected instruction:
Code: Select all   Expand viewCollapse view
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
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Object variable not set error message

Postby nicari » Fri Feb 25, 2011 8:56 am

Thanks very much, Bernhard
I corrected the spelling as you recommended.
But the subsequent line still makes trouble:
Code: Select all   Expand viewCollapse view
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
nicari
 
Posts: 27
Joined: Mon Jan 03, 2011 3:14 am

Re: Object variable not set error message

Postby B Marcelly » Fri Feb 25, 2011 9:35 am

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
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Object variable not set error message

Postby nicari » Fri Feb 25, 2011 11:38 am

Thanks,
Now it works fine
Egbert
ooo-build 3.2.1.4 on PCLinusOS 2010
nicari
 
Posts: 27
Joined: Mon Jan 03, 2011 3:14 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests