Autonumber not executing any of my code to check a checkbox (1 Viewer)

bmaccess

Member
Local time
Yesterday, 22:40
Joined
Mar 4, 2016
Messages
78
Hi. I need help with the following please.

When I type in a number in the StudentBookIssue_ID the code runs perfectly and the checkbox get checked.
When I set the field to an autonumber the number gets inserted but the code does not get execute. And my
IssuedLearner.Value stay false.


Private Sub StudentBookIssue_ID_AfterUpdate()
If (StudentBookIssue_ID.Value = True) And (IssuedLearner.Value = False) Then
IssuedLearner.Value = True
End If

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:40
Joined
Oct 29, 2018
Messages
21,646
Can you post a sample copy of your db with test data?
 

Mike Krailo

Well-known member
Local time
Today, 01:40
Joined
Mar 28, 2020
Messages
1,114
But an autonumber doesn't require user interaction on a form. So how is the after update going to fire? The autonumber is created at the table level, not the form level. You are probably on another field when the ID populates, right?

Much better to use the FORMS Before Update for something like this.
 

bmaccess

Member
Local time
Yesterday, 22:40
Joined
Mar 4, 2016
Messages
78
I am still busy with my book control application. When a book is issued an autonumber will be assigned and a checkbox must be activated to indicate that a book was issued and the store count must update by subtracting 1 from the total. Not sure if you understand my scenario.
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:40
Joined
Sep 21, 2011
Messages
14,666
So if new record set that checkbox?
However you should be calculating available books, not storing available book numbers.
 

bmaccess

Member
Local time
Yesterday, 22:40
Joined
Mar 4, 2016
Messages
78
I am on this form. When I add the book Top Class Life Skills 1 i must get a autonumber in Student BookIssue_ID and the checkbox must be ticked.
as the book above it. Current I have typed 1,2,3,4,5,6,7 and the issued checkbox was ticked and total_in_store was was update.
I need to achieve exactly the same if an autonumber was added in Student BookIssue_ID. Is it possible to achieve same effect with an autonumber?
1695587424377.png
 

bmaccess

Member
Local time
Yesterday, 22:40
Joined
Mar 4, 2016
Messages
78
So if new record set that checkbox?
However you should be calculating available books, not storing available book numbers.
The total of books are calculate. The total_in_store is being deducted by 1 if a book is issued and added by 1 if a book is returned
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:40
Joined
Sep 21, 2011
Messages
14,666
The total of books are calculate. The total_in_store is being deducted by 1 if a book is issued and added by 1 if a book is returned
That is not calculated, that is storing the result? :(
Never advised to do thar.
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:40
Joined
Sep 21, 2011
Messages
14,666
I am on this form. When I add the book Top Class Life Skills 1 i must get a autonumber in Student BookIssue_ID and the checkbox must be ticked.
as the book above it. Current I have typed 1,2,3,4,5,6,7 and the issued checkbox was ticked and total_in_store was was update.
I need to achieve exactly the same if an autonumber was added in Student BookIssue_ID. Is it possible to achieve same effect with an autonumber?
View attachment 110013
As per post #2, post your db.
 

Mike Krailo

Well-known member
Local time
Today, 01:40
Joined
Mar 28, 2020
Messages
1,114
I am on this form. When I add the book Top Class Life Skills 1 i must get a autonumber in Student BookIssue_ID and the checkbox must be ticked.
as the book above it. Current I have typed 1,2,3,4,5,6,7 and the issued checkbox was ticked and total_in_store was was update.
I need to achieve exactly the same if an autonumber was added in Student BookIssue_ID. Is it possible to achieve same effect with an autonumber?
Autonumbers do not execute code, events do. When the autonumber gets set automatically (that's what autonumbers do), then that is done in code so it never will trigger anything like you are assuming. I already explained that in my previous post. You have disabled the autonumber in the provided screenshot. If you enable it, it will populate automatically and as long as you have the master/child links correctly set, everything should function correctly.

The only problem with your code posted in the first post is that you are testing if the (StudentBookIssue_ID.Value = True), which doesn't make any sense if the ID field is an autonumber. Autonumbers are numbers and not true/false values. So your logic is flawed. Since we don't know what the logic is supposed to be, you have to determine what you want to happen and adjust accordingly.

It looks like you could just set the checkbox default to True and be done with it. You seem to be checking that box no matter what.
 

bmaccess

Member
Local time
Yesterday, 22:40
Joined
Mar 4, 2016
Messages
78
Autonumbers do not execute code, events do. When the autonumber gets set automatically (that's what autonumbers do), then that is done in code so it never will trigger anything like you are assuming. I already explained that in my previous post. You have disabled the autonumber in the provided screenshot. If you enable it, it will populate automatically and as long as you have the master/child links correctly set, everything should function correctly.

The only problem with your code posted in the first post is that you are testing if the (StudentBookIssue_ID.Value = True), which doesn't make any sense if the ID field is an autonumber. Autonumbers are numbers and not true/false values. So your logic is flawed. Since we don't know what the logic is supposed to be, you have to determine what you want to happen and adjust accordingly.

It looks like you could just set the checkbox default to True and be done with it. You seem to be checking that box no matter what.
Thanks much appreciated for the info.
 

Users who are viewing this thread

Top Bottom