1 (edited by reteinformatica 2023-04-02 20:17:59)

Topic: Print a selected record in a tablegrid

Hello everyone, thank you because you are reading my request and I am sure you will help me.
In my project I have a table called "Dipendenti" with various fields. I inserted a button to print only one record of a tablegrid. I looked at the example project found on the phone book site and tried the "SQL Report". There is no link to any other table in this table.
The code I wrote in the SQL report is this:

SELECT
Dipendenti.CAP,Dipendenti.Città,
Dipendenti.Cognome,
Dipendenti.DataNascita,Dipendenti.e-mail,
Dipendenti.Indirizzo,Dipendenti.InternoTelefono,
Dipendenti.Nome,Dipendenti.NumeroTelefono,
Dipendenti.Settore,Dipendenti.TitoloStudio,

FROM Dipendenti

WHERE Dipendenti.id = $id

Other try:

SELECT
Dipendenti.CAP,Dipendenti.Città,
Dipendenti.Cognome,
Dipendenti.DataNascita,Dipendenti.e-mail,
Dipendenti.Indirizzo,Dipendenti.InternoTelefono,
Dipendenti.Nome,Dipendenti.NumeroTelefono,
Dipendenti.Settore,Dipendenti.TitoloStudio,
Dipendenti.id

FROM Dipendenti

WHERE Dipendenti.id = $Dipendenti  

Will you kindly help me understand where it is that I am wrong? Thank you very much.

Re: Print a selected record in a tablegrid

Try it like this

SELECT
Dipendenti.CAP,
Dipendenti.Città,
Dipendenti.Cognome,
Dipendenti.DataNascita,
Dipendenti.e-mail,
Dipendenti.Indirizzo,
Dipendenti.InternoTelefono,
Dipendenti.Nome,
Dipendenti.NumeroTelefono,
Dipendenti.Settore,
Dipendenti.TitoloStudio,
Dipendenti.id

FROM Dipendenti

WHERE Dipendenti.id = {tablegrid1} 

(assuming that the tablegrid that contains the data is called 'tablegrid1').
Derek.

3 (edited by reteinformatica 2023-04-03 06:57:14)

Re: Print a selected record in a tablegrid

Hi derek, when I press the button I get the error I put in the attachment. It would seem to refer to the "e-mail" field But I put this field in the "Search" button. which displays the search data in the TableGrid.

Post's attachments

Attachment icon errore.jpg 18.74 kb, 38 downloads since 2023-04-03 

Re: Print a selected record in a tablegrid

I also enter the project, the problem is in the last TabSheet "Employees".

Post's attachments

Attachment icon Decora.zip 388.85 kb, 114 downloads since 2023-04-03 

Re: Print a selected record in a tablegrid

I think I've discovered the problem: I think they don't like the - in the field names.

6 (edited by sparrow 2023-04-03 08:17:01)

Re: Print a selected record in a tablegrid

Hi Derek, reteinformatica


Field names with spaces, other characters, and generally need to be quoted around 'e-mail', 'e mail', etc.
Fixed SQL query and report fields.

...
'Dipendenti'.'e-mail',
...
Post's attachments

Attachment icon Decora1-fix.zip 401.2 kb, 113 downloads since 2023-04-03 

7 (edited by reteinformatica 2023-04-03 08:41:57)

Re: Print a selected record in a tablegrid

Hi, sparrow, I had felt that the - had something to do with it. In fact, I removed it and the error was gone. Thank you for the elucidation and correction.

Re: Print a selected record in a tablegrid

Hello again ).

In your script

var nuovo : string;

procedure frmInserimentopc_OnShow (Sender: TObject; Action: string);
begin
  if action = 'NewRecord' then nuovo := 'new'
end;

procedure frmInserimentopc_bSalvaenuovopc_OnAfterClick (Sender: TObject);
begin
  if nuovo = 'new' then
    begin
      start.butInseriscipc.click;
      frmInserimentopc.edNomepc.setfocus;
    end else frmUtenti.close;
end;
...
...

the variable 'nuovo' is set to 'new' when a new entry is added and then remains throughout the program for new entries and review of entries.
The variable is used in different forms.

Re: Print a selected record in a tablegrid

I sparrow, I didn't understand what you want to say me. Is this not good enough?

Re: Print a selected record in a tablegrid

Fixed

Variable 'nuovo',
Corrected form names in procedures.

Post's attachments

Attachment icon Decora2.zip 393.51 kb, 96 downloads since 2023-04-03 

Re: Print a selected record in a tablegrid

Hi Fabio, Hi Sparrow,
What Sparrow is saying is that you have set 'nuovo' to be 'new' but no where do you clear it.
Your code should be

procedure frmInserimentopc_OnShow (Sender: TObject; Action: string);
begin
  if action = 'NewRecord' then nuovo := 'new' else nuovo := '';
end;

(and wherever else in your script you are using 'nuovo').
Derek.

Re: Print a selected record in a tablegrid

Sorry Sparrow - I didn't see that you'd already replied.
Derek.

13 (edited by sparrow 2023-04-03 10:12:47)

Re: Print a selected record in a tablegrid

Derek, It's all right, It's better to answer two than no one. )))
In addition, decisions can be different and then there is a choice.

Re: Print a selected record in a tablegrid

Hi derek and sparrow, I got it. It would seem to work that way too, though, is that normal?

Re: Print a selected record in a tablegrid

When it works incorrectly, of course it also works, but not as it should.
So far it hasn't been critical, but who knows.
for example this moment:


procedure frmInserimentopc_bSalvaenuovopc_OnAfterClick(Sender: TObject);
begin
   if nuovo = 'new' then
     begin
       start.butInseriscipc.click;
       frmInserimentopc.edNomepc.setfocus;
     end else frmUtenti.close;



Procedure for form "frmInserimentopc" and close another form "frmUtenti". The error is purely technical when copying code from one place to another.

Re: Print a selected record in a tablegrid

All clear, I made the right correction I just don't know how to thank both of you. But don't think you have gotten rid of me, surely before the end of the project I am doing I will have to ask you for something else smile

Re: Print a selected record in a tablegrid

Above I posted the second version with all the fixes. decora2.
We'll help in any way we can.

Re: Print a selected record in a tablegrid

Thank you!

Re: Print a selected record in a tablegrid

Èh yes I am here again. The new problem I found is on the print report. It is always found in the last TabSheet "Dipendenti." if I click on the print button for the selected record the report opens without any problems, if, however, I click on the "Stampa tutti" button the report opens full of errors and with all fields saying "File not found." It seems illogical, but this may be my wrong thinking, to do two reports for the same table. However, I don't understand why one report opens well and the other one doesn't. Thank you!

Post's attachments

Attachment icon Decora.zip 389.22 kb, 87 downloads since 2023-04-03 

20 (edited by reteinformatica 2023-04-03 18:04:22)

Re: Print a selected record in a tablegrid

I've made some changes, and this time I have the reverse problem: Clicking on "Stampa tutti" the report works, if I click on "Stampa selezionato" gives me all the errors and "File not found".
By the way I see in the errors that the field "Città" shortened it to "Citt" for me. Better not to use accented letters?

https://prnt.sc/cfi3jegd7ON9

Post's attachments

Attachment icon Decora.zip 389.39 kb, 104 downloads since 2023-04-03 

Re: Print a selected record in a tablegrid

Hi Fabio,
The data that you are passing through to the report, although it comes from the same table, is not called the same thing.
Have a look at the attached screenshot.
For example, in the case of one of the reports your field name in Fast Report is 'nome' but the field that is being sent to Fast Report is called 'dipendenti.nome.
This is because you are using 'report' to generate the report in one instance and 'report sql' in the other (I am not sure why you are using 'report sql' as I would have thought 'report' was easier).
Derek.

Post's attachments

Attachment icon screen1.jpg 109.5 kb, 37 downloads since 2023-04-03 

22 (edited by reteinformatica 2023-04-03 18:29:51)

Re: Print a selected record in a tablegrid

Hi derek, thanks for the usual elucidation. I used reportSQL because seen in the example "Phone Book" And I thought it was the best thing.
I have now changed only to "Report" using the same report but doing so obviously prints me the whole list and not just the selected record.

23 (edited by sparrow 2023-04-03 18:36:59)

Re: Print a selected record in a tablegrid

Hello everyone again.

It's all about how we send the data to the report.
In a SQL query, there is such a thing as an alias.
Everything is very simple:
Like this - SELECT 'Dipendenti'.'CAP' ... in the response, the column name will be called as the name of the column 'CAP'
And like this - SELECT 'Dipendenti'.'CAP' AS "Dipendenti.CAP" ... the column will get the alias "Dipendenti.CAP"

Therefore, in your request for a single record, the name of the column, and the program generates an alias from the name of the database.column name


SELECT
'Dipendenti'.'CAP' AS "Dipendenti.CAP", 
'Dipendenti'.'Città' AS "Dipendenti.Città",
'Dipendenti'.'Cognome' AS "Dipendenti.Cognome",
'Dipendenti'.'DataNascita' AS "Dipendenti.DataNascita",
'Dipendenti'.'Indirizzo' AS "Dipendenti.Indirizzo",
'Dipendenti'.'InternoTelefono' AS "Dipendenti.InternoTelefono",
'Dipendenti'.'Nome' AS "Dipendenti.Nome",
'Dipendenti'.'NumeroTelefono' AS "Dipendenti.NumeroTelefono",          
'Dipendenti'.'email' AS "Dipendenti.email",
'Dipendenti'.'Settore' AS "Dipendenti.Settore",
'Dipendenti'.'TitoloStudio' AS "Dipendenti.TitoloStudio",
'Dipendenti'.'id'             

FROM 'Dipendenti'

WHERE 'Dipendenti'.'id' = {tbDipendenti}  

Re: Print a selected record in a tablegrid

Hi sparrow, it should be so:

SELECT

'Dipendenti'.'CAP' AS "Dipendenti.CAP",
'Dipendenti'.'Città' AS "Dipendenti.Città,       
'Dipendenti'.'Cognome' AS "Dipendenti.Cognome",            
'Dipendenti'.'DataNascita' AS "Dipendenti.DataNascita",
'Dipendenti'.'Indirizzo' AS "Dipendenti.Indirizzo",                    
'Dipendenti'.'InternoTelefono' AS "Dipendenti.InternoTelefono",                  
'Dipendenti'.'Nome', AS "Dipendenti.Nome",                                         
'Dipendenti'.'NumeroTelefono' AS "Dipendenti.NumeroTelefono",           
'Dipendenti'.'email' AS "Dipendenti.email",                                       
'Dipendenti'.'Settore' AS "Dipendenti.Settore",                   
'Dipendenti'.'TitoloStudio' AS "Dipendenti.TitoloStudio",                
'Dipendenti'.'id'             

FROM 'Dipendenti'

WHERE 'Dipendenti'.'id' = {tbDipendenti}

25 (edited by reteinformatica 2023-04-03 18:45:18)

Re: Print a selected record in a tablegrid

Ah sorry, I didn't see you changed post.
Yes, it works! Thanks so much