Topic: Access violation error while configuring report button

Hello,
I am trying to create a Report(SQL) to summarize the records made during a visit of a patient. However, I am getting an “Access violation......” error, when the Print Prescription button is clicked in form AA_Form_007_OPD_VISIT_REC. I am therefore unable to open the Report Designer. How to resolve the issue?
Regards,
Eyeman

Post's attachments

Attachment icon My_Eyes_61.zip 703.24 kb, 230 downloads since 2021-07-23 

2 (edited by sparrow 2021-07-23 15:04:32)

Re: Access violation error while configuring report button

Hi,
something wrong with the component DTP_Time_VISIT (in the attached file )

Field Calendar incorrect value button100

Post's attachments

Attachment icon err1.jpg 116.16 kb, 94 downloads since 2021-07-23 

Re: Access violation error while configuring report button

Hello Sparrow,
The DTP_Time_VISIT field is saving correctly to table AA_002_REC_Visits, field Time_Visit. Something may be wrong with  Report(SQL) script.... I don't know.
Regards,
Eyeman

Post's attachments

Attachment icon DTP_Time_Visit.JPG 173.96 kb, 93 downloads since 2021-07-23 

4 (edited by sparrow 2021-07-23 16:53:23)

Re: Access violation error while configuring report button

Change field CALENDAR - button100 in the component DTP_Time_VISIT ... and be happy

button100 - wrong value. and report access violation

Post's attachments

Attachment icon err2.jpg 116.48 kb, 83 downloads since 2021-07-23 

Re: Access violation error while configuring report button

your project modif

Post's attachments

Attachment icon my-modif.zip 711.27 kb, 209 downloads since 2021-07-23 

Re: Access violation error while configuring report button

Hello Sparrow,
Thanks for the modification. The access violation error is resolved, but they're still some syntax errors in the Report(SQL) script. Yet to reach the Report Designer.
Regards,
Eyeman

Post's attachments

Attachment icon syntax_error.JPG 71.22 kb, 96 downloads since 2021-07-23 

7 (edited by derek 2021-07-24 12:05:42)

Re: Access violation error while configuring report button

Hi Eyeman,
As Sparrow has already reported, the access violation error was due to you trying to associate a 'time' field with a 'calendar' object - logically, calendars are associated with 'date' fields, not 'time' fields.
With regard to the report(sql) script, I had a very quick look and there are a number of errors (there may be others, I didn't go through the whole script)..
1.  On lines 6 and 29 you are calling calculated fields (age and cf_staffman).  Calculated fields don't actually exist at the database level, they are just temporary calculations when the program runs so cannot be directly referenced as part of an sql statement..
2.  On line 7, there is a space imbedded in the field 'name_ of_doctor;  MVD accepts this but as an sql statement, it will almost certainly produce an error.
3.  On line 50, you have left a comma after the last selected field (impression).
These can be easily corrected.  However, the bigger issue is your 'where clause' which has inner joins to 67 tables!  I question what sort of response times you'll experience with such a query - if it works at all (but as you know from previous posts, I have reservations about the number of tables and forms that you're using generally). 
Is there really data in all 67 tables that relate to the initial record that you want to report on?  You could always use 'left outer join' instead but again, it's the number of joins that concerns me.
With regard to 'good practice' (and I'm sure everyone has different ideas so it's just a personal opinion), I would suggest that you 'start small' with such a query -  include just a couple of tables and, if it's working, then build it up gradually and testing as you go along.  Writing it all at once and then finding out that it doesn't work is a bit of a waste of time and makes trying to debug it extremely difficult.
Derek.

Re: Access violation error while configuring report button

Hello Derek,
Thank you for the guidance. I have made the suggested corrections and some progress. The report needs to include data contained under the tab Clinical_Records in the form AA_Form_007_OPD_VISIT_REC. This data is saved in 11 tables. There are many Look-up tables linked to these tables. I have attached a pdf of the report format that I wish to achieve. However, I am stuck with error messages, that I'm unable to resolve. Can you have a look, please?
Regards,
Eyeman

Post's attachments

Attachment icon My_Eyes_61edit.zip 576.89 kb, 223 downloads since 2021-07-25 

9 (edited by derek 2021-07-25 16:33:53)

Re: Access violation error while configuring report button

Hello Eyeman,
I have had another quick look and there are still a number of syntax errors in your report(sql) script - I haven't been through it all but a couple are:
1.  you are still referencing calculated fields (cf_staffname)
2.  missing commas between selected fields (field 'os')
3.  references to tables and fields that don't seem to exist (table L010?)
4.  fields selected twice
5.  fields ambiguously defined (for example, the field 'notes' is referenced in both aa_030 and aa_057).
However, trying to correct the above errors (and possibly more that I haven't bothered checking) is, in my opinion, a bit of a waste of time and effort. 
Having now seen the .pdf that you included in your attachment detailing how you want the information to appear, I believe what is needed is a main report (the patient's OPD visit) with a number of subreports (with each subreport corresponding to your .pdf sections of clinical symptoms, medical history, visual acquity, glass power etc etc).
I don't use FastReport very much but I imagine that would be quite a complicated report to produce.
Instead of the main report / subreports approach, a much simpler alternative might be to write a number of discrete reports (one for the 'OPD visit', one for the associated 'clinical symptoms', one for the associated 'medical history' etc etc) and then chain them together (in other words, you run the first report and when it finishes, it automatically calls the next one etc etc);  this has 2 major advantages:
1.  you could probably write them using 'report' (rather than 'report(sql) which would also get round the calculated fields problem).
2.  you could run a specific report, if required, rather than the whole 'suite'.
I can't see any other practical way of achieving what you want although there may be other Forum members who can think of a different approach.
Derek.

Re: Access violation error while configuring report button

Hello Derek,
Thank you again for your time and invaluable advice.  I would like to follow the simpler approach and create discrete subreports from separate tables using Report action. However, I am not sure how the creation of the first report would automatically call the next report creation. Also how to combine discrete reports generated into a 1-page  summary report (that is needed to be handed to the patient)?
Regards,
Eyeman

11 (edited by derek 2021-07-25 22:51:36)

Re: Access violation error while configuring report button

Hi,
Have a look at the attached example.
In it, you can run each of the 3 reports separately or use the 'chain'.  The 'chain' is simply a bit of script that calls each of the reports in turn.
If you need a 1 page summary report, it depends on what information you want to give to the patient;  just try not to end up recreating the same problem that you had when using report(sql).
As a 'rule of thumb', if you can display the summary information in a tablegrid, then you can pass it through to the report (in essence, your tablegrid becomes the dataset that is used by FastReport).
Derek.

Post's attachments

Attachment icon follow on reports.zip 349.02 kb, 241 downloads since 2021-07-26 

12 (edited by eyeman303 2021-07-27 15:10:28)

Re: Access violation error while configuring report button

Hello Derek,
Thank you for the program and guidance. I am working on your advice. I have attached a  report generated from a different program used at another facility. The 1-page summary report needs to contain these details. How do I get this summary from different tables to a tablegrid? Report(SQL) action may be one way to get these data, but it's easy to falter.
Regards,
Eyeman

Post's attachments

Attachment icon similar_report.jpg 157.43 kb, 81 downloads since 2021-07-27 

Re: Access violation error while configuring report button

Hello,
I was trying to create a small report (AA_Form_007_OPD_VISIT_REC.Button13) displaying the glass power of the patient. However, on preview, the data is not displayed. Ditto for Summary Report  (AA_Form_007_OPD_VISIT_REC.Button1). Where is it going wrong?
Regards,
Eyeman.

Post's attachments

Attachment icon My_eyes61_glasspower.zip 543.02 kb, 211 downloads since 2021-08-13 

14 (edited by sparrow 2021-08-13 21:25:31)

Re: Access violation error while configuring report button

Hi,
Tables for all occasions )))

Incorrect use of JOIN in SQL query.
You are using an INNER JOIN which requires the data in both tables to match. You currently do not have data in many tables.

Report (SQL) Button13
INNER JOIN leads to errors when JOIN tables:


inner join AA_012_REC_DOCTORS
on AA_012_REC_DOCTORS.id = A002.id_AA_012_REC_DOCTORS, ( in AA_012_REC_DOCTORS.id not found records)


inner join LU_001_Salutation
on LU_001_Salutation.id = A001.id_LU_001_Salutation, ( in A001.id_LU_001_Salutation - NULL)


inner join LU_022C_Dsph_Intermediate AS L022C
on L022C.id = A006.id_LU_022C_Dsph_Intermediate. ( in A006.id_LU_022C_Dsph_Intermediate -NULL)


Enter correct data in these tables and table AA_002_REC_Visits, AA_001_REC_PATIENT_REG, or use the LEFT JOIN for these three JOIN first.

15 (edited by eyeman303 2021-08-14 17:29:53)

Re: Access violation error while configuring report button

Hello Sparrow,
Thank you for the guidance. I changed to Left join for these tables, but still no data. Perhaps other Inner Joins override the Left Joins. I changed all to Left Join and now the data appears in Preview of FastReport. However, all data from child tables are displayed and not for the desired A002.id. How to solve this issue? Need AND clause? Left Join may be ideal, as often the child tables may have a null value.

Post's attachments

Attachment icon My_eyes61LeftJoin.zip 543.02 kb, 217 downloads since 2021-08-14 

16 (edited by sparrow 2021-08-15 04:42:53)

Re: Access violation error while configuring report button

As Derek says I was waiting for this question
Derek did a lot for your project and maybe my questions and answers will help you, him and me.
You understood my answer correctly (Left Join may be ideal, as often the child tables may have a "null" value). But you still have to enter data correctly into your tables.
1.You have a lot of tables and it seems to me that you do not quite understand how JOIN works with all this.
   Without this, you will not be able to display data correctly.
   I recommend reading the help about all JOINs in SQL, especially about NULL and INER JOIN, LEFT JOIN.
2. You see A002.id as you set its ID in WHERE. But JOIN matching  data from other tables. Any condition in JOIN ... ON ... forces data to be matching values according to the equality ... = .... What you want to see is shown to you. Please read the help for all JOINs in SQL. It is not difficult.
3. Try to specify specifically in WHERE or SELECT what you want to get from ANY table. The last record by id, by time or other parameters ... I understand that it is difficult, there are many tables.
4. LEFT JOIN will most likely be perfect. But only in the case when not all tables are filled in correctly (I'm talking about "NULL" and "n / a" and ...). But this will not help to display correct data if it is missing.



When you read the JOIN help and try it yourself, be specific about what is wrong and what you want to see.  I or someone else will try to help. The forum reads and can help you better experts than me.

Sorry for my and google english).

Post's attachments

Attachment icon sql join.jpg 88.25 kb, 93 downloads since 2021-08-15 

Re: Access violation error while configuring report button

Hello Sparrow,
Thank you for the response. I am indebted to you and all the learned Forum members and Derek, in particular for guiding me at every step in my projects. Definitely, I will read more about JOINs. The Report needs to display the data entered in all the child tables for an OPD_ID on a particular date. The A002.id is unique for each OPD_ID and date, and id_A002 is a foreign key in all the child tables. This query is getting additional data for A002.id  referring to a different OPD_ID and date. Why is this happening?
Regards,
Eyeman.

18 (edited by sparrow 2021-08-16 09:38:03)

Re: Access violation error while configuring report button

eyeman303 wrote:

Hello Sparrow,
Thank you for the response. I am indebted to you and all the learned Forum members and Derek, in particular for guiding me at every step in my projects. Definitely, I will read more about JOINs. The Report needs to display the data entered in all the child tables for an OPD_ID on a particular date. The A002.id is unique for each OPD_ID and date, and id_A002 is a foreign key in all the child tables. This query is getting additional data for A002.id  referring to a different OPD_ID and date. Why is this happening?
Regards,
Eyeman.

Hi,
Show exactly which column from the query or which row, which data ... you think is wrong. Then we can discuss.
In the file what your request returns (partially).

PS
see answer below

19 (edited by sparrow 2021-08-16 09:40:58)

Re: Access violation error while configuring report button

Try to fix your request like this.
Add last line "AND ..."
Hope this solves your problem)

...
where
A002.id = $id
AND A006B.id_LU_010_Eye_Select=A006.id_LU_010_Eye_Select

Re: Access violation error while configuring report button

Hello Sparrow,
That's a fabulous solution! That's the condition ( AND...) I was searching for, but could not figure it out. The query now produces the desired output. Thanks a ton for helping me out. I can now develop the report further and strive to accomplish the desired result.
Regards,
Eyeman

Re: Access violation error while configuring report button

You are welcome

I will repeat again. )))  I recommend reading help about JOINs in SQL.
This AND ... part of the JOIN. Your two tables A006B and A006 have a common id_LU_010_Eye_Select.

Re: Access violation error while configuring report button

Hello Sparrow,
I agree fully with your advice. JOINs are so critical in SQL! Here adding the AND clause using the common field  id_LU_010_Eye_Select, ensures that the correct row (=  id_LU_010_Eye_Select) is selected from both A006 and A006B. So the visual acuity details and Refraction details of the same eye is joined from these 2 tables. This is what I understand.
Regards,
Eyeman