Solved Log routine issue (1 Viewer)

mloucel

Member
Local time
Today, 15:50
Joined
Aug 5, 2020
Messages
156
Following advise from Moderators..

Some code in my 1st Program is from @arnelgp whom I respect a lot.

I have attached a mock database, contains no valid information, but is similar to my final database.
I do understand that there are many possible programming errors but for what is worth it works for me, and I will clean it once I got all done.
-- My main issue right now:
- I want to create a LOG of actions done in the database, so I can keep a little track on somethings done, I am a rookie, so I search a lot for solutions that I can use and learn, I found a nice routine in youtube to:
1) Add a couple of records when a user adds a new record, date/time, the user name, the ID of the record and the word NEW
2) Will add as well when someone Edits a record, saving the old value and the new value [I hope], the ID, date/time, user name, and the control value before and after.
-- The problem
I followed instructions as specified in youtube but when my Module [LogFunctionModule] Function AuditChanges tries to save the data to the LogT [Log table] I got errors, I have changed the code a few times but I cannot figure out what is wrong, and I am barely trying the function on my ADD record routine.
My Logic:
On frmPatientCharts I added a routine on BeforeUpdate event, either is a NEW record or EDIT, [I WILL NOT DELETE records]
this calls the AuditChanges function
once called generates Error 3201: You cannot add or change a record because a related record is required in table 'Charts'
I Have no Idea why, table charts should not be in error since I am tying to save data to table LogT
I've changed a lot in the code, but I saved it as remark so that I know what was there before.

I have attached my database in hope someone can guide me in the right direction, thanks you all gurus for your help.
 

Attachments

  • Charts.zip
    564.9 KB · Views: 73

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:50
Joined
Aug 30, 2003
Messages
36,126
It's because you've related the two tables:

1686591010574.png
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:50
Joined
Feb 19, 2002
Messages
43,293
and I will clean it once I got all done
No, you won't. No novice ever does. You'll be too afraid to break something.

Take it from someone who has been writing code since probably before you were born, clean up as you go. If I change a section of code, I might comment it out because I don't know if the new version will be better but once I go with the new version, I delete the old code. Keeping it only makes the remaining code harder to read and leaves unanswered questions. If I decide to keep the old, commented code, I document why I am keeping it.

Just look at the way a good cook works, The good cook always cleans up after himself and doesn't dirty every pot and dish in the kitchen and then leave it to crust in the sink. The good cook does NOT leave out temperature sensitive ingredients to spoil either.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:50
Joined
Aug 30, 2003
Messages
36,126
Never in my life thought about that, yes I got rid of the relationship that should have never been there. Yes is working as intended, thanks so much @pbaldy

Happy to help!
 

Users who are viewing this thread

Top Bottom