Topic: Textbox value from Select with case

Hi guys,

I am struggling to write the following script to autofill an email address field if the field is empty. I keep getting errors that a ")" is missing next to the first ||

The query works well in SQLStudio if we replace the variable +name+ by an actual one.

var
email: string;
name: string;


procedure Details_OnShow (Sender: string; Action: string);
begin
 Name := details.EditName.sqlValue; // get current Name
 email := SQLExecute ('select firstname ||'.' || lastname || '@company.com' from users where lastname= '+name+'');
  if details.EditEmail.Text<>'' then details.EditEmail.Text:= email;
end;

Re: Textbox value from Select with case

try this query

  email := SQLExecute ('select firstname ||''.''|| lastname || ''@company.com'' from users where lastname= '+name);
Dmitry.

Re: Textbox value from Select with case

The query works just fine, thank you for fixing the syntax.

Now the if condition does not work even when replacing if details.EditEmail.Text <>''  by if details.EditEmail.sqlValue <>''

Whatever I set, the value is always replaced by the query result smile

current code is:

var
email1: string;
email2: string;
name: string;


procedure Details_OnShow (Sender: string; Action: string);
begin
 Name := details.EditName.sqlValue; // get current Name

 email1 := SQLExecute ('select firstname ||''.''|| lastname || ''@company.com'' from users where lastname= '+name); //Autofill email address
 email2 := SQLExecute ('select email from users where lastname= '+name); //existing email address
  if details.EditEmail.sqlValue <>'' then details.EditEmail.Text:= email1 else details.EditEmail.Text:= email2;
end;

Re: Textbox value from Select with case

Event OnShow occurs before filling form by the query.


I need to develop new event, like OnAfterData for form.

Dmitry.

Re: Textbox value from Select with case

Ok, waiting for next update then! smile

6 (edited by tcoton 2015-11-23 13:51:35)

Re: Textbox value from Select with case

How could I update the value of this textbox when changing it from another form?

I have tried to hide and show the form while editing but when coming back, the value disappears instead of updating!

7 (edited by mathmathou 2015-11-23 23:22:55)

Re: Textbox value from Select with case

I think the key is the OnChange event on the source Combobox

On the same Form you could do :

procedure Form1_ComboBox2_OnChange (Sender: string);
begin
    Form1.ComboBox1.dbItemID := Form1.ComboBox2.dbItemID;
end;

On two different Forms :

procedure Form2_ComboBox1_OnChange (Sender: string);
begin
    Form1.ComboBox1.dbItemID := Form2.ComboBox1.dbItemID;
end;
I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Textbox value from Select with case

It is not a combobox but a textbox

Re: Textbox value from Select with case

My mistake...

Why did I wanted it to be a ComboBox ? Don't know smile

I'll rework my answer

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

10 (edited by mathmathou 2015-11-24 08:42:01)

Re: Textbox value from Select with case

If it's OK to close the second Form to trigger the text transfer, you can do :

procedure Form2_OnClose (Sender: string; Action: string);
begin
    Form1.Edit1.Text := Form2.Edit1.Text;
end;

If there is text present in Form1.Edit1 it will be replaced.



If you need to keep the second form open but still update the first one, you could use :

procedure Form2_OnMouseMove (Sender: string; Shift, Alt, Ctrl: boolean; X, Y: Integer);
begin
    Form1.Edit1.Text := Form2.Edit1.Text;
end;

Not really "by the book" but it works.

Just after typing the text, as soon as the mouse is moved, the text is transfered

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Textbox value from Select with case

Actually it is even worse... The value I display in Form1 is in a text box but is modified in Form2 by a combobox.


I fixed it by re-executing the SQL query on Form2 closure. Thank you for the hint:

procedure Data_Edition_OnClose (Sender: string; Action: string);
begin
     details.SIM_Sttus.text:= SQLExecute ('select colum from table t left join table2 s on t.id_status=s.id where t.id= '+other_TextBox_Value);
end;