| View previous topic :: View next topic |
| Author |
Message |
Andrew Golightly General User

Joined: 27 Feb 2006 Posts: 22
|
Posted: Tue Feb 28, 2006 6:19 am Post subject: selection of a combobox item displaying a value in a textbox |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3622 Location: Columbus, Ohio, USA
|
Posted: Wed Mar 01, 2006 9:08 pm Post subject: |
|
|
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 |
|
 |
DrewJensen Super User


Joined: 06 Jul 2005 Posts: 2616 Location: Cumberland, MD
|
Posted: Wed Mar 01, 2006 11:44 pm Post subject: |
|
|
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 |
|
 |
Andrew Golightly General User

Joined: 27 Feb 2006 Posts: 22
|
Posted: Thu Mar 02, 2006 4:03 am Post subject: |
|
|
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
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3622 Location: Columbus, Ohio, USA
|
Posted: Thu Mar 02, 2006 5:27 am Post subject: |
|
|
| 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
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 |
|
 |
Andrew Golightly General User

Joined: 27 Feb 2006 Posts: 22
|
Posted: Thu Mar 02, 2006 7:18 am Post subject: |
|
|
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 ) 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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3622 Location: Columbus, Ohio, USA
|
Posted: Thu Mar 02, 2006 8:28 am Post subject: |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3622 Location: Columbus, Ohio, USA
|
Posted: Thu Mar 02, 2006 8:36 am Post subject: |
|
|
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 |
|
 |
Andrew Golightly General User

Joined: 27 Feb 2006 Posts: 22
|
Posted: Fri Mar 03, 2006 3:38 am Post subject: |
|
|
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 |
|
 |
Andrew Golightly General User

Joined: 27 Feb 2006 Posts: 22
|
Posted: Fri Mar 03, 2006 4:02 am Post subject: |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3622 Location: Columbus, Ohio, USA
|
|
| Back to top |
|
 |
Andrew Golightly General User

Joined: 27 Feb 2006 Posts: 22
|
Posted: Fri Mar 03, 2006 6:22 am Post subject: |
|
|
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 |
|
 |
Andrew Golightly General User

Joined: 27 Feb 2006 Posts: 22
|
Posted: Mon Mar 06, 2006 3:38 am Post subject: |
|
|
Hey Andrew,
Thanks so much for that example. Looking through the code in your macro, I've definitely learnt something new and useful
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3622 Location: Columbus, Ohio, USA
|
Posted: Mon Mar 06, 2006 5:29 am Post subject: |
|
|
| 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 |
|
 |
|