Two Functions one event....

CEH

Curtis
Local time
Today, 12:12
Joined
Oct 22, 2004
Messages
1,187
I have discovered the reason for a problem I am having and need some advice. I have an application that I am running a validation function on... similar to "mousetrap".... On this app I am also running an "Audit Trail" both calls are on the "Before Update" THIS is what is causing my problem! I am thinking the "Audit Trail" code must be on this event to capture the "Before" value of the changed field....Not sure on the validate..... Suggestions? Other events to use?
Thanks
 
You are in the right event for both functions. Is there a reason you can't hold off the AuditTrail until *after* it passes validation?
 
I had considered that RG... But doesn't it need to be on an event BEFORE the record is updated? So it can write the old value?.... What event should I put the call for the audit trail on?
Thanks
 
My thoughts were that you not allow the AuditTrail code to run until your form passes validation. So it is either Cancel = True or Call AuditTrail code.
 
RG..........I'm lost....If you have a minute can you take a look... Seeing is sometimes easier than explaining :) Off the main menu click "View Applicant Information" it all takes place there....... Thanks
 

Attachments

I made some changes Curtis. See if it works as you would expect. It can get confusing if you mix single line and milti-line code. I would suggest just using multi-line code and loose the colons.
 

Attachments

Well RG, I'm still getting the same error message and no record in the "frmAuditTrail"
How I check is this...... Bring up a record..... delete one of the dropdowns....say "Hours" Click the "Validate/Close" should give me back error message to file the field...It does.. so far so good..... I pick something different from the dropdown... click "Validate/Close" again... It's OK... but then I get "Operation is not supported for this type of object 3251" click ok....... it closes...... no record of change in "frmAuditTrail"........ Got me baffled... I pull it apart and the validation works and the audit trail works....but combine them and the 3251 error........:confused:

PS........ I have also found it only makes this error on the combo boxes!
 
Last edited:
I see the problem now Curtis. It will take a bit to figure out what is going on.
 
Thank you for your time RG! I know if anyone can figure out my goof you can. I know these combos where a problem in the validation also........Had to Go into design view for tblInterview and change the FK on the combos default value to "0" for it to work............. Thanks again.
 
Just tried a second one RG, the one by Candace Tripp..... her example had comboboxes..... but the list is in the property... not from a query.....So it works...for her......
 
I've been working on this all night... and I have found if you put the validation function on a command button and not the BeforeUpdate event...it all works.... but together....they don't.

Update.........
RG......... I think I may have it.
This goes off what you were saying before...... running the validation then the audit trail....
Since they bothed worked independently I had to try to get them to work together.......
I think this code will slide into what you have... I did a new db....put code on piece by piece...
ended up calling the audit trail from the validation code..... it works in my strped down DB... Now I need to see if it works in the big one.
But I just added two lines.....

Code:
Public Function FieldValidate()
'Place an asterisk (*) in the Tag Property of the text boxes you wish to validate.
'Then in the BeforeUpdate Event of the form, copy/paste the following:
'modified to add Label text to message box instead of field name
'ctl.Controls(0).Caption instead of ctl.Name
'This will make much more sense to a user

Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control, Source As String, Cancel As Integer, Answer As Variant

nl = vbNewLine & vbNewLine

For Each ctl In Me.Controls

If ctl.ControlType = acTextBox Or ctl.ControlType = acOptionGroup Or ctl.ControlType = acComboBox Then
If ctl.Tag = "*" And Trim(ctl & "") = "" Then
msg = "Data Required for '" & ctl.Controls(0).Caption & "' field" & nl & _
"You can't save this record until this data is provided" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Answer = "False"
Me.txtValid = Answer
Cancel = True
  Exit For
    Else: Answer = "True"
    Me.txtValid = Answer
  
        End If
            End If
                Next
                Set ctl = Nothing
        Call AuditTrail(Me, InterviewID)
End Function
All I added was the "Set ctl = Nothing" (I am thinking those combos were picking up a value from someplace) And then the Call AuditTrail.........
Now I know I'm not that hot of a coder..(yet) :) But let me know if this looks good to you.
Thanks
 
Last edited:
Hi Curtis,

Looking at the Form’s control and AuditTrail, my thoughts were the control’s old value might be the problem there.

Did the changes work for you?

I've been working on this all night... and I have found if you put the validation function on a command button and not the BeforeUpdate event...it all works.... but together....they don't.
Snip......
Thanks
 
No it didn't work..............:mad:
So what problem are you referring to?
 
Curtis,
Have you looked at Allen Browne's method of implimenting an Audit Trail? He uses transactions and either kills or commits at the end. I've used it for years and it works flawlessly. Just a thought. I still don't know why what you have does not work properly but I've got several computers limping right now and need to spend the time necessary to get them running properly. I'll get back to this as soon as I have some time. Creating an Audit Log
 
Last edited:
Thanks for the look RG... I looked at the one by Allen Browne.... looks fine...... BUT... I already have the tables in place for this one and the client is already using it :) So making this one work is a must... I am sure it has to do with having to change the combobox default value to null..... but not sure why it's behaving the way it is. I'm finished with all the clients updates so I can now start pullig this one apart to see if I can get it working.
 
Hey Curtis,
I just found this in my "open" threads file - which is filled with tons of other stuff to make it harder to find these. :eek: I hope you were able to resolve this.
 

Users who are viewing this thread

Back
Top Bottom