Why does the calculation of Midway return zero when Recount returns 774
Code:Reccount = AllnamesX2.RecordCount MsgBox "Reccount = " & Reccount Midway = (RecordCount \ 2) ' - 4) MsgBox " Midway =" & Midway
Why does the calculation of Midway return zero when Recount returns 774
Code:Reccount = AllnamesX2.RecordCount MsgBox "Reccount = " & Reccount Midway = (RecordCount \ 2) ' - 4) MsgBox " Midway =" & Midway
My guess is VBA sees RecordCount as a variable not recordset property.
Maybe should be: Midway = (Reccount \ 2)
or: Midway = (AllnamesX2.RecordCount \ 2)
You should have Option Explicit at top of every code module. https://www.fmsinc.com/MicrosoftAcce...ons/index.html
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
One tiny error- try "Midway = (Reccount / 2)"
Cheers,
Al
I doubt it is an error. Division with \ drops remainder and returns integer. Can accomplish same with Int() function.
Last edited by June7; 07-01-2024 at 09:17 AM.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Ah, I see.
I thought we were just talking about the integer divisionwhich was mentioned as an error?
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
>>>Why does the calculation of Midway return zero when Recount returns 774
Code:
Reccount = AllnamesX2.RecordCount
MsgBox "Reccount = " & Reccount
Midway = (RecordCount \ 2) ' - 4)
MsgBox " Midway =" & Midway
I think I've figured it out- it would have been easier to have the complete code establishing your recordset.
What seems to have happened is that before your "MsgBox " Midway =" & Midway statement, you probably closed your recordset, which would of course lead to an AllnamesX2.RecordCount of 0, since it's closed.
You correctly assigned the actual recordcount to your "Reccount" variable, but then in line 3 you again use the recordcount incorrectly in 2 ways: 1) which should be "AllnamesX2.RecordCount" since just RecordCount would be wrong (Dave alluded to that), and 2) anyhow AllnamesX2.RecordCount is now probably closed.
You should thus use the "Reccount" variable which actually does hold the 774 number, if set up before closing the recordset.
0/2 is 0, which is what you are getting.
I've never used the \ division in my 29 years of working with Access... learn something new every day! I doubt I'll be using it though- as June7 stated, Int() works nicely.
Regards,
Al
alborg, Reccount variable receives value from AllnamesX2.RecordCount and there is no following line to close recordset. So a correct reference to recordset property should still work.
I did a test to confirm that VBA just sees RecordCount as a variable if it is not qualified with recordset name. And since OP's code executes, I conclude RecordCount is not declared and there is no Option Explicit line.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
All, don't ya just hate this? 10 responses (with #3 being the fix) and NOTHING more from OP. Even volunteers do hate to waste their time.
Post 3 is not the fix. See post 2.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
There isn't total agreement. My suggestion retains \ and does not replace with /.
Post 3 possibly deviates from OP's intent.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.