Solved Public sub is not called (1 Viewer)

Trond Hoyem

New member
Local time
Today, 09:26
Joined
Jun 22, 2021
Messages
13
Hi
I am adding some activity logging to my database. For this I have created a public sub in my module "CommonFunctions" called "activity" What it basically does is just to add a record in the activity table with the user name and a short text describing what has been done, like "log in", "deleted article" and so on.

Now, my problem is that in one of my forms (a subform to the article list-form) I am not able to add anything to the activity log. I normally call the public sub like this:
Code:
    Call activity("Added new article", Me.txtArticleNumber)

When I do this within the subform, nothing happens in the activity log:
Code:
Private Sub Delete_Click()
    If MsgBox("Dette vil slette denne tag for alle artikler. Det er ikke mulig å angre denne handlingen. Vil du fotsette?", vbYesNo + vbExclamation + vbDefaultButton2, "Sletter tags") = vbYes Then
        Call CommonFunctions.activity("Deleted article tag.", "")
        DoCmd.SetWarnings False
       
        DoCmd.OpenQuery "qryDeleteTag"
        Forms!frmEditArticle!sfrmEditTags.Requery
       
        DoCmd.SetWarnings True
    Else
        Exit Sub
    End If
End Sub

Any idea why?
 

June7

AWF VIP
Local time
Yesterday, 23:26
Joined
Mar 9, 2014
Messages
5,463
Why are you sure it does not run? Did you set break point and step through code?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 08:26
Joined
Feb 19, 2013
Messages
16,604
depends on the parameters of your activity sub - if the second one is numeric (on the basis of your example uses txtArticleNumber which implies numeric) then your call needs to use 0 rather than ""
 

Trond Hoyem

New member
Local time
Today, 09:26
Joined
Jun 22, 2021
Messages
13
Why are you sure it does not run? Did you set break point and step through code?
I did not try that, but the next lines in the same procedure are executed, so I don't really see why this one is not executed.
 

Trond Hoyem

New member
Local time
Today, 09:26
Joined
Jun 22, 2021
Messages
13
depends on the parameters of your activity sub - if the second one is numeric (on the basis of your example uses txtArticleNumber which implies numeric) then your call needs to use 0 rather than ""
ArticleNumber is a string. The second parameter works fine in other forms with "" when there is no spesific reference to be added.
 

Trond Hoyem

New member
Local time
Today, 09:26
Joined
Jun 22, 2021
Messages
13
I did not try that, but the next lines in the same procedure are executed, so I don't really see why this one is not executed.
I tried now, and it skips this line for some reason, and execute the lines after it.... It does not stop at the break point.
The MsgBox appears, and the record is deleted byt the query that is run after pressing "Yes". The form is also updated after the code is run.

So everything in the code works, except callin the Public sub.
 

Trond Hoyem

New member
Local time
Today, 09:26
Joined
Jun 22, 2021
Messages
13
OK, this is embarrassing...

I have for some reason two forms with almost identical names, and one is not in use. Probably I have made a new and better one at some point. I was looking in the code of the wrong form. When pasting it into the correct form, it works.

Sorry to bother you with this nonsense.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:26
Joined
Feb 19, 2002
Messages
43,213
You might want to turn off "Name Auto Correct", if you have a tendency to rename objects and create replacements. You will find that in some cases references to frmABC will be changed to xxfrmABC assuming you add xx as a prefix to indicate a deleted object. That is what I do to drop the object to the bottom of the list where I can do cleanup later to get rid of unused objects.
 

Trond Hoyem

New member
Local time
Today, 09:26
Joined
Jun 22, 2021
Messages
13
You might want to turn off "Name Auto Correct", if you have a tendency to rename objects and create replacements. You will find that in some cases references to frmABC will be changed to xxfrmABC assuming you add xx as a prefix to indicate a deleted object. That is what I do to drop the object to the bottom of the list where I can do cleanup later to get rid of unused objects.
That surely sounds like a good idea. I will adopt that practice.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:26
Joined
Feb 19, 2002
Messages
43,213
Good move:) you can always turn it on if you have lots of changes to make and you want it to help. Just be sure you understand HOW it actually works (most people don't) before turning it back on.
 

Users who are viewing this thread

Top Bottom