show strReason only when Screen.Active.OldValue is not Null

Sniper-BoOyA-

Registered User.
Local time
Today, 15:05
Joined
Jun 15, 2010
Messages
204
Good Afternoon,

Ive added a new function to my database which logs the changes made using forms and saves it to a table 'Audit'. (The function is being called in the BeforeUpdate event.)



Everything works just fine, but theres just one thing i cant seem to figure out.

When a change is being made, the user will get an inputbox where he/she has to enter a reason why she applied the change in question. So far so good. But that InputBox also appears when theres no data in the record yet, which makes it unnecessary to give a reason ,since theres nothing being changed.

Ive tried to, add the IsNull function:

Code:
If IsNull(Screen.ActiveControl.OldValue) = False 
Then strReason = InputBox("Reden voor wijziging? (Max 40 tekens)")

But it turns out that it has no effect whatsoever. It still asks me to give a reason, even though the old value is Null...

Does anyone have an idea what im doing wrong? Here is the code of the function TrackChanges()

Code:
Public Function TrackChanges()
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strCtl As String
Dim strReason As String
strReason = InputBox("Reden voor wijziging? (Max 40 tekens)")
strCtl = Screen.ActiveControl.Name
strSQL = "SELECT Audit.* FROM Audit;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If rs.RecordCount > 0 Then rs.MoveLast
With rs
.AddNew
rs!FormName = Screen.ActiveForm.Name
rs!Veldnaam = strCtl
rs!datum = Date
rs!Tijd = Time()
rs!OudeWaarde = Screen.ActiveControl.OldValue
rs!NieuweWaarde = Screen.ActiveControl.Value
rs!Gebruiker = fOSUserName
rs!LoggedIn = CurrentUser()
rs!Computer = FindComputerName
rs!Reason = strReason
.Update
End With
Set db = Nothing
Set rs = Nothing
End Function
 
Look into Me.Dirty and Me.NewRecord. Also look into the Dirty event of the form.

Edit: Didn't you ask this question ask on another thread?
 
Last edited:
To be honest, yes i have asked the same question in the VBA thread. But unfortunately no one has replied to my post since the 16th, and i am getting desperate when it comes to this 'problem'..

I just dont get why it cant be fixed by a simple check that checks if the Screen.ActiveControl.OldValue is Null..

But i will look into the me.dirty and me.newrecord, but since ive never used them before it can take a while..

Thanks for replying in such a short notice.
 
Double posting isn't something that we like in this forum and I'm sure other forums don't tolerate. I would advise you follow-up your post in the other thread.

Check the help files for an explanation on those properties, it gives a good explanation. Or try searching the forum and you will find some examples.
 
Ok, then i would like to opologize for double posting. I guess ill look into those properties. Thanks.
 
That's not a problem, it just helps the search engine and causes less grief for the admins and helpers. :)

Give me the link of your other thread and I'll keep an eye out if you need further help.
 
Got it. I will keep an eye out (when I can) if you get stuck.
 

Users who are viewing this thread

Back
Top Bottom