| View previous topic :: View next topic |
| Author |
Message |
ejohnson442 Newbie

Joined: 11 Nov 2008 Posts: 3
|
Posted: Thu Dec 04, 2008 2:37 am Post subject: List Box Error: Inadmissible value or data type. |
|
|
I'm using Open Office 3 on Windows Vista. I've been searching the web for a week now without finding a resolution to the following problem:
I populate a list box on my form as follows:
Data field: "ID"
Type of list contents: sql
List content: SELECT "Media", "ID" FROM "Media" ORDER BY "Media" ASC
Bound field: 1 (I've changed this during testing but without results)
I've borrowed code from this forum/other places and arrived at the following:
Sub applyfilter(oEvent)
dim oTxt, oListModel, myCurrentId
oTxt = oEvent.Source.SelectedItem()
msgbox (oTxt)
oListModel = oEvent.Source.getModel()
myCurrentId = oListModel.ValueItemList(oListModel.SelectedItems(0))
msgbox (myCurrentId)
end Sub
I've tried various versions of the above code based on this forum and nothing works. The results are always the following:
Inadmissible value or data type
Index out of defined range
The error message seems to suggest that perhaps the ValueItemList is not being properly populated. I would think this to be a very common task. What am I doing wrong? |
|
| Back to top |
|
 |
Voobase OOo Advocate


Joined: 21 Nov 2007 Posts: 400 Location: Australia
|
Posted: Thu Dec 04, 2008 6:00 am Post subject: |
|
|
Hi there,
What are you trying to achieve with the macro? With the SQL which is in your listsource, it seems the listbox would be displaying the field "media" and binding the field "ID" into the field "ID", which is a field in the table (of the form) that the listbox is sitting in. This is because you have selected "ID" as the data field. I am hoping that the field "ID" (from the table of the form that the listbox is sitting in) is not a primary key field, as you would be changing the primary key value of the row of data of your form whenever you operated the listbox.
If you are trying to use the listbox to retrieve a certain row of data from your database you would need to go about it another way. You could create a "dummy table" (of 1 row of data only)and base your mainform on this table. The listbox could also sit in this form and when it is operated store its "ID" value in a field in the dummy table. You then can create a SubForm and base this on the table you wish to display. You can then use a link/join between the dummy table's field and the "ID" field of the SubForm's table. A simple macro (to reload subform) would then be required to display the record you wished. Have a look at these threads for more details.... http://www.oooforum.org/forum/viewtopic.phtml?t=72134
http://user.services.openoffice.org/en/forum/viewtopic.php?f=39&t=10036
There are also other ways to go about this but they probably require more macro. Let me know if it wasn't this and you problem was different.
Cheers
Voo |
|
| Back to top |
|
 |
ejohnson442 Newbie

Joined: 11 Nov 2008 Posts: 3
|
Posted: Thu Dec 04, 2008 11:10 am Post subject: |
|
|
Hmmmmm,
I guess my code fragment is a bit confusing as to my intent. The code fragment demonstrates my attempt to acquire the underlying value from a listbox selection.
The full scope of what I'm trying to do is to have a form for user input. Two listboxes are available from which to select a media type (ex., magazine1, magazine2, magazine3, etc.) and the print language (ex., chinese, spanish, amharic, etc.) of the requested media. The listboxes serve as straightford lookup (so it's ok that the "ID" is the primary key) objects.
Upon completing some prelimary client information, the appropriate selection is made using the before mentioned listboxes. Form submission creates a record, part of which contains the "ID" from each selected listbox items.
Since I am able to acquire the item selected from each listbox, I know I could use that info and generated a query to get the "ID" from the appropriate table but that's kinda kludgy. Obviously, I'd prefer to avoid that if at all possible but I could live with it.., maybe...
But if I could get the SelectedValue for the SelectedItem (as is so common for listboxes in most other UI implementations I've used), everything would be neat, tidy and meet the standards for modern programming protocol. Please tell me this can be done.
(Thank you so much for your prompt reply!) |
|
| Back to top |
|
 |
Voobase OOo Advocate


Joined: 21 Nov 2007 Posts: 400 Location: Australia
|
Posted: Fri Dec 05, 2008 4:36 am Post subject: |
|
|
Hi again,
Luckily most things are achievable in Base. Sometimes its the long way you take until it dawns on you a better way.
| Quote: | | The code fragment demonstrates my attempt to acquire the underlying value from a listbox selection. |
If you want to obtain, in your macro code, the value you are binding to the table, i.e the "ID" you would use one of these....
| Code: | myCurrentId = oListModel.boundfield.value
myCurrentId = oListModel.boundfield.string
myCurrentId = oListModel.boundfield.Int |
you might need to use before the above line
| Code: | | oListModel.CurrentValue | gives you the displayed value
If it was this... don't worry, it took me a long time to find it the first time!
Have you downloaded XRAY yet? http://www.ooomacros.org/dev.php#101416 It's a great aid for exploring the properties and methods of controls and forms etc. You would just put this line in your code...
and you are supplied all the properties of the listbox. If you have the SDK downloaded then you are also provided an explanation of each property or method.
Here's a thread that you might find useful... It gives you some other useful methods of the listbox like "commit" and "refresh"... (btw you can't use "refresh" with a combobox, you have to use "reload" for the whole form)
http://www.oooforum.org/forum/viewtopic.phtml?t=74229
Also if you want to see an example database which uses a couple of listbox's and also demonstrates copying the values with a macro using SQL etc, have a look at this thread.....
http://www.oooforum.org/forum/viewtopic.phtml?t=72062
(btw for the example you need to load the macro in separately. It's not kept with the form. Instructions in the thread).
Cheers
Voo |
|
| Back to top |
|
 |
ejohnson442 Newbie

Joined: 11 Nov 2008 Posts: 3
|
Posted: Sun Dec 07, 2008 7:30 pm Post subject: |
|
|
Thank you very much for your assistance. The links to sample code/projects you provided are invaluable. It seems that the issues I have are have to do with the relationships between the data sources for the forms/components. I'm disappointed with the complexity surrounding this issue but..., sigh, I'm working through it.
Thanks again for you help! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|