OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

selection of a combobox item displaying a value in a textbox

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
Andrew Golightly
General User
General User


Joined: 27 Feb 2006
Posts: 22

PostPosted: Tue Feb 28, 2006 6:19 am    Post subject: selection of a combobox item displaying a value in a textbox Reply with quote

Hi,

This seems really simple, but it ain't working for me. I have a form based on a single table. There is a combo box that is populated by a column (title) in that table. I then also have a text box that I want to display the value from the description column for that record when the corresponding title is selected.

Currently, on selecting a value from the combo box, there is no change to the value of the text box. Using the record controls below I can iterate through the values in the text box.. but this isn't what I'm after.

Can you help?
thanks,
Andrew
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Wed Mar 01, 2006 9:08 pm    Post subject: Reply with quote

Just so that I understand the problem. You have a single table similar to the following:


===Table1===
Title
What ever
Description


You have a form that contains a combo-box and a text box.
The combo-box contains data from the Title column in Table1.
When a title is selected in the combo box, you want the description to be displayed in the text field.

I assume that the Title is unique.

I have only solved this problem when more than one table is involved. I assume that the Combo-Box is not really associated with the table. By this, I mean that if you change the value in the combo box, it does NOT cause a value in some related field to change. In other words, someone has simply set all possible values into the combo box and now you can see them. Is this correct?

I assume that you will need to use an event handler that is called when a new value is selected. The event handler would need to lookup the corresponding Description in the table.

I will see if I can find time to find a solution, assuming that you do not figure one out before I do... I think that it is straight forward, it is just the details... Always the details...
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
DrewJensen
Super User
Super User


Joined: 06 Jul 2005
Posts: 2616
Location: Cumberland, MD

PostPosted: Wed Mar 01, 2006 11:44 pm    Post subject: Reply with quote

I was going to say something...but not sure if three people named Andrew are allowed to be on a single thread...
_________________
Blog - http://baseanswers.spaces.live.com/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Andrew Golightly
General User
General User


Joined: 27 Feb 2006
Posts: 22

PostPosted: Thu Mar 02, 2006 4:03 am    Post subject: Reply with quote

hey Andrew (pitonyak)

You've pretty much got it perfectly summarised. There is also an id column to ensure uniqueness,

I think you're right. There'll be an event followed by some macro code that I don't know how to do yet Smile

It's not a high priority at the moment. My first goal is to get a many-to-many project working. Working from this thread: http://www.oooforum.org/forum/viewtopic.phtml?t=21697&start=0

Thanks for your interest,
Andrew
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Thu Mar 02, 2006 5:27 am    Post subject: Reply with quote

Quote:
I was going to say something...but not sure if three people named Andrew are allowed to be on a single thread...

It makes plausible deniability easier Laughing

I thought about this last night while sleeping (I used to solve math problems in my sleep and then I would wake up and write down the solution so that I would not forget it) and I think that this can be done without a macro.

Probably just need a subform that relates to the combo-box. Need to think more....
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Andrew Golightly
General User
General User


Joined: 27 Feb 2006
Posts: 22

PostPosted: Thu Mar 02, 2006 7:18 am    Post subject: Reply with quote

I have a slightly off-topic question, but hopefully still related enough to remain in this thread.

I've started to work with macros refencing tables on the form. I've added a combobox populated from the task table I have. It displays the title value. There is a button next to it. The idea is that when the button is clicked, the ID for that record can be extracted through macro code. Sounds basic (xpuse the pun Laughing) but I'm not sure how the api works yet. Any good pointers to useful api/code snippet section?

The code currently looks like so:
Code:

sub addTask( oEv as Object )
   dim sAddSQL as String
   dim oXrefForm as Object
   dim projectsViewForm as Object
   dim projectID as String
   dim taskID as String
   dim Statement as Object
   
   ' get the form that is using our tasksView table
   tasksViewForm = oEV.Source.Model.parent.getbyname("tasksView")
   oXrefForm = oEV.Source.Model.parent
   
   ' get the key fields for current record of the rowset attached to this form
   sProjectID = tasksViewForm.getColumns.getByName( "projectId" ).getString
   sTaskID = [WHAT DO I PUT HERE??]
   
   ' create our insert sql statement
   sAddSQL = "insert into Projects2Tasks (project2TasksProjects,projects2TasksTasks) values(" & sProjectID
   sAddSQL = sAddSQL & "," & sTaskID & ")"
   
   ' Issue the sql statement to the database
   Statement = projectsViewForm.ActiveConnection.CreateStatement
   Statement.executeUpdate( sAddSQL )
   oXrefForm.reload

end sub


thanks.
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Thu Mar 02, 2006 8:28 am    Post subject: Reply with quote

Read the new section titled Relations in a single table. I solved the problem using macros rather than figure out how to relate the fields to make it automatic.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Thu Mar 02, 2006 8:36 am    Post subject: Reply with quote

A comment on your code. Remember that you are doing things that I have not done... The aother Andrew knows more about this I think...

You declare your variables as
Code:
   dim projectID as String
   dim taskID as String

And them use them as sProjectID and sTaskID, which is spelled differently. Add "Option Explicit" to the top of the module and you will catch all of these types of errors.

I am not certain how to get the sTaskID because I am not certain where the value is stored.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Andrew Golightly
General User
General User


Joined: 27 Feb 2006
Posts: 22

PostPosted: Fri Mar 03, 2006 3:38 am    Post subject: Reply with quote

right. option explicit added.
Quote:
Read the new section titled Relations in a single table.

In which document? I didn't find it in your macro nor your base document when I searched for that string.
Back to top
View user's profile Send private message
Andrew Golightly
General User
General User


Joined: 27 Feb 2006
Posts: 22

PostPosted: Fri Mar 03, 2006 4:02 am    Post subject: Reply with quote

on the staskID value.. i have a table that has 3 columns:

taskId, taskTitle, taskDescription

I have a combobox that is populated by the taskTitle values. Then when a value is chosen and the button next to it is pressed, I would like to obtain the associated taskId value in order to update another table.

The combobox is a child of the form tasksViewForm.. so I would like some code similar to this:
Code:
 
sTasktitle = tasksViewForm.getComboBox.getSelectedValue
sTaskID = lookupId(sTasktitle)


You get the idea? Where do I look up the functions/methods for BASIC for openoffice?

thanks. A
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Fri Mar 03, 2006 5:28 am    Post subject: Reply with quote

I updated the document yesterday with an example just for you so you need to grab the latest copy http://www.pitonyak.org/database/AndrewBase.odt

I demonstrate how to get a value from a combo box there, well, at least from the event generated by the combo box.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Andrew Golightly
General User
General User


Joined: 27 Feb 2006
Posts: 22

PostPosted: Fri Mar 03, 2006 6:22 am    Post subject: Reply with quote

I've changed my combobox to a listbox, so now it appears I can use a select statement to get both the title and id, but only display the title.

Still not sure how to get the id value though using basic code..

Thanks for the updated doc Andrew. I'm starting to work my way through it.
Back to top
View user's profile Send private message
Andrew Golightly
General User
General User


Joined: 27 Feb 2006
Posts: 22

PostPosted: Mon Mar 06, 2006 3:38 am    Post subject: Reply with quote

Hey Andrew,

Thanks so much for that example. Looking through the code in your macro, I've definitely learnt something new and useful Smile

I've started looking at listboxes as they refer to bound fields.. and being able to select, say, 2 fields from a table. What I'm wondering is, programatically, can one not only get the displayed value, but also the other selected values from the sql query? I'll be displaying the title in the text box, but would like to also obtain the id value associated with it.

I can get the value in the list box with the following code:
Code:

   oXrefForm = oEV.Source.Model.parent
   MsgBox oXrefForm.getbyname("TaskTitleListBox").getCurrentValue


Can I get the id value straight away, or do I need to use this value to re-query my table?

Hope you had a good weekend. Andrew
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Mar 06, 2006 5:29 am    Post subject: Reply with quote

Quote:
Can I get the id value straight away, or do I need to use this value to re-query my table?

I have no idea. I usually figure out these problems by creating an example and then I inspect the objects. If you email me a base document that contains a form with a list box configured as you say, I can inspect the object to see if I can find a way to do this. I will be very busy this week and I am not certain how much free time I will have.

andrew@pitonyak.org
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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