I have a problem with the Categories counter for the Category field on the form. When form load , the counters not show number category A Or B Or C , but the category counter appears in the first record on Office 2019
Please help to run all the counters
Note I had previously set it up in another database and it was working fine on Office 2013
i attach database
You have a useless line in two of your VBA event routines. The statement
Code:
DIM CboXX, CC, CB, CA As String
has two flaws. One, you only declared one string - CA. The other three variables are Variants. That's because you need that var AS datatype in EACH segment of the DIM statement. Any named element in a DIM that doesn't include the "AS" portion is a variant.
But that error actually doesn't hurt since you don't USE those variables anyway. Your code is using Me.CboXX, Me.CA, Me.CB, and Me.CC - all of which are valid controls on your form. Since you always use the Me. prefix, the variables never get referenced.
I can tell you that the reason the counters don't show in the LOAD routine is that IF statement that checks the value of Me.CboXX, which technically on a freshly loaded form isn't anything until a selection is made with the combo box. That is, unless I missed a default (I admit I didn't check), a combo has no value until it is used OR unless you use the long form of combo reference that lets you see the value in any row and column of the combo box.
When I use the combo box, it loads up a counter, though I noticed that the count it loaded wasn't correct. Haven't figured that out yet.
You have a useless line in two of your VBA event routines. The statement
Code:
DIM CboXX, CC, CB, CA As String
has two flaws. One, you only declared one string - CA. The other three variables are Variants. That's because you need that var AS datatype in EACH segment of the DIM statement. Any named element in a DIM that doesn't include the "AS" portion is a variant.
But that error actually doesn't hurt since you don't USE those variables anyway. Your code is using Me.CboXX, Me.CA, Me.CB, and Me.CC - all of which are valid controls on your form. Since you always use the Me. prefix, the variables never get referenced.
I can tell you that the reason the counters don't show in the LOAD routine is that IF statement that checks the value of Me.CboXX, which technically on a freshly loaded form isn't anything until a selection is made with the combo box. That is, unless I missed a default (I admit I didn't check), a combo has no value until it is used OR unless you use the long form of combo reference that lets you see the value in any row and column of the combo box.
When I use the combo box, it loads up a counter, though I noticed that the count it loaded wasn't correct. Haven't figured that out yet.
Thank you very much for your wonderful analysis and your convincing response. But I have used these counters and they were working fine on Office 2013. But I don't know what happened when I tried to repeat the experience on Office 2019. Do you have any idea to correct this error using the if function?
Thank you for your great effort and your interest in answering my question. I would like you to help me correct this function. I am an amateur and not a professional like you, I have used my simple knowledge and I want you to give me the names of the sources that I rely on to write vba in an easy way. thank you very much
Thank you for your great effort and your interest in answering my question. I would like you to help me correct this function. I am an amateur and not a professional like you, I have used my simple knowledge and I want you to give me the names of the sources that I rely on to write vba in an easy way. thank you very much
I noticed an error when using your code. Where I counters are the same number. I would like the first counter is the symbol "a", the second counter is the symbol "b" and the third counter is the symbol "c". As in the attached picture.
I misinterpreted my point, I sincerely apologize
Seems to work fine for me as you had it? I would have a common sub though and just call it from where you need it?
Why not just show all the counts regardless of combo? What is this trying to do?
Code:
Private Sub CboXX_AfterUpdate()
Call CalcCat
End Sub
Private Sub CboXX_Change()
Call CalcCat
End Sub
Private Sub Form_Load()
'Call CalcCat
End Sub
Sub CalcCat()
Me.CA = DCount("cat", "atbl", "cat='a'")
Me.CB = DCount("cat", "atbl", "cat='b'")
Me.CC = DCount("cat", "atbl", "cat='c'")
End Sub
Seems to work fine for me as you had it? I would have a common sub though and just call it from where you need it?
Why not just show all the counts regardless of combo? What is this trying to do?
Code:
Private Sub CboXX_AfterUpdate()
Call CalcCat
End Sub
Private Sub CboXX_Change()
Call CalcCat
End Sub
Private Sub Form_Load()
'Call CalcCat
End Sub
Sub CalcCat()
Me.CA = DCount("cat", "atbl", "cat='a'")
Me.CB = DCount("cat", "atbl", "cat='b'")
Me.CC = DCount("cat", "atbl", "cat='c'")
End Sub
If they were used in the same exact code in Office 2013, they suffered the same exact problem. Because you prefixed them with Me. and because their names are exactly the same as four of the five controls on your form, they were never used.
Code:
DIM CboXX, CC, CB, CA As String
...
If Me.CboXX = "a" Then ...
The VARIABLE CboXX is NOT repeat NOT used by Me.CboXX because they are in totally different contexts. Me.CboXX refers to the CONTROL on the form, which happens to have the same name as the variable. They are TWO DIFFERENT THINGS. With the Me. prefix, you use the control. Without the prefix, you would use the variable. That prefix is called a "qualifier" in that it qualifies the location of something. You use it to differentiate between two things with identical names but different locations.
I'll agree that things worked the same way in Ac2013 and other versions of Access with regard to this declaration. Which is to say that the variables would not have made a difference then, either. But Gasman's comments and suggestions are spot-on. Arnelgp's comments are also correct.