1 (edited by jeffmtl@hotmail.com 2021-12-15 21:02:21)

Topic: Using SQL and pushing data into a ComboBox

Hi

This is a similar question that I had but with a twist (I previously could use a GRID to get an SQL reference but now I am using a different Table and only have a combobox as a point of connection)

I want to force an answer into a combobox from a different table. It works with a Textbox, but not with Combobox

The reason behind my crazy, is that I can get the users to use the search button with the combobox (otherwise I wouldn't know how to get around this problem)..

Here are 2 lines of code similar in function but information placed in 2 different formats (TEXTBOX and COMBOBOX) I just get a blank in combobox..

*** From a selection of a condobox = cdClientResource,  you will look up the table dbManager of ManagerNameCombined and place it in Combobox

Push to a text box (ClientManagerText)

# 1

fmClient.ClientManagerText.text:=SQLExecute('Select ResManagerText FROM dbResource WHERE id= '+fmclient.cbClientResource.sqlvalue);

Push to a combo box (cbClientManager.)

# 2
fmclient.cbClientManager.text:=SQLExecute('Select ResManagerText FROM dbResource WHERE id= '+fmclient.cbClientResource.sqlvalue);


see ATTACHED PDF. I find it hard to explain my problem.

Post's attachments

Attachment icon sql-ComboBox.pdf 414.94 kb, 365 downloads since 2021-12-15 

Re: Using SQL and pushing data into a ComboBox

Hi Jeffmtl,
Not sure I entirely follow what you're doing so this might not be an answer for you.
Try replacing
fmclient.cbClientManager.text:=SQLExecute('Select ResManagerText FROM dbResource WHERE id= '+fmclient.cbClientResource.sqlvalue);
with
fmclient.cbClientManager.dbitemid :=SQLExecute('Select ResManagerText FROM dbResource WHERE id= '+fmclient.cbClientResource.sqlvalue);
Basically, in your script you need to link between the two tables using their IDs/Foreign Keys;  your script is trying to match a piece of text with an ID (which is why you don't find anything).
The text (in your example 'Barbra Walters')  is simply whatever fields you choose to display on frmclient (which could be any field - or a combination of them - as in the example {managerfirstname} {managerlastname}).
Hopefully, the attached example will clarify this.
Derek.

Post's attachments

Attachment icon jeffcombobox.zip 338.17 kb, 367 downloads since 2021-12-16 

Re: Using SQL and pushing data into a ComboBox

Hello everyone
Derek, if he wants to add ResManagerText text ('Barbra Walters') not ID then:
Not fmclient.cbClientManager.dbitemid: = SQLExecute ('Select ResManagerText ...


Use procedure dbAddRecord (id: integer; text: string) -  Adds a record to the component and assigns it the specified id.
The record will not be added to the database.
example
textvar: = (SQLExecute ('Select ResManagerText ...);
fmclient.cbClientManager.dbAddRecord (1, textvar);


or create links as you suggest