Topic: Print saves blank record...

1. Form1 click on ADD button to add a new record.
2. On Form2 click on PRINT button with or without entering any data.
3. After clicking on PRINT button it saves the record blank or with entered values without clicking on SAVE button.
4. Clicking on CANCEL button on Form2 doesn't make any difference as it seems save triggered once PRINT button clicked.


How to avoid saving a record without clicking on save button in this circumstance?


Sample project is attached:

Post's attachments

Attachment icon Print Saves Balnk Record.zip 5.07 kb, 360 downloads since 2017-03-30 

Adam
God... please help me become the person my dog thinks I am.

Re: Print saves blank record...

Hello.


Print button also save record, because use data from database, not from form.


You can prevent it, example:

procedure Form2_Button2_OnClick (Sender: string; var Cancel: boolean);
begin
    if Form2.Button1.dbGeneralTableId = -1 then Cancel := true;
end;
Dmitry.

Re: Print saves blank record...

DriveSoft wrote:

Hello.


Print button also save record, because use data from database, not from form.


You can prevent it, example:

procedure Form2_Button2_OnClick (Sender: string; var Cancel: boolean);
begin
    if Form2.Button1.dbGeneralTableId = -1 then Cancel := true;
end;

Thanks a lot Dmitry.....
The above stops saving onClick of print button. However, print button appears as active button, clicking on it doesn't do anything. I tried to add info message

procedure Form2_Button2_OnClick (Sender: string; var Cancel: boolean);
var
buttonSelected : Integer;
begin
  buttonSelected :=MessageDlg('Only saved records can be printed.', mtInformation,mbOK,0);
    begin
    if Form2.Button1.dbGeneralTableId = -1 then Cancel := true;
    end;
end;

Unfortunately, info message is displayed on show record too beside showing print preview. I couldn't get it right to stop info message showing on show record / print.


Then I used disable print button on new record, and enable on show record.

procedure Form1_Button2_OnClick (Sender: string; var Cancel: boolean);
begin
    Form2.Button2.enabled := false;
end;

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    Form2.Button2.enabled := true;
end;

I'm not sure if this is the correct approach tho.

Adam
God... please help me become the person my dog thinks I am.

Re: Print saves blank record...

Check it out

procedure Form2_Button2_OnClick (Sender: string; var Cancel: boolean);
begin
    if Form2.Button1.dbGeneralTableId = -1 then 
    begin
        Cancel := true;
        MessageDlg('Only saved records can be printed.', mtInformation,mbOK,0);
    end;    
end;
Dmitry.

Re: Print saves blank record...

Thanks a lot Dmitry.....................

Adam
God... please help me become the person my dog thinks I am.