Results 1 to 15 of 15
  1. #1
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18

    Correct syntax for Miway of Recount


    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

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    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.

  3. #3
    alborg is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Location
    Virginia, USA
    Posts
    11
    One tiny error- try "Midway = (Reccount / 2)"

    Cheers,
    Al

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    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.

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by alborg View Post
    One tiny error- try "Midway = (Reccount / 2)"

    Cheers,
    Al
    Exactly what Option Explicit will catch.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by davegri View Post
    Exactly what Option Explicit will catch.
    But it wouldn't Dave, would it?, as that is quite valid with \
    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

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by Welshgasman View Post
    But it wouldn't Dave, would it?, as that is quite valid with \
    Well, in the first row Recordcount is dependent on AllnamesX2, but not in the third row. I don't see how VBA could know what that was without a DIM if Option Explicit is present.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Ah, I see.
    I thought we were just talking about the integer division which 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

  9. #9
    alborg is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Location
    Virginia, USA
    Posts
    11
    >>>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

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    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.

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    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.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    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.

  13. #13
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by June7 View Post
    Post 3 is not the fix. See post 2.
    Post2 and 3 explicitly agree. I should have said post2 and 3.

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    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.

  15. #15
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by June7 View Post
    There isn't total agreement. My suggestion retains \ and does not replace with /.

    Post 3 possibly deviates from OP's intent.
    Missed that and learned something new. Difference between / and \ arithmetic operators.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 03-01-2021, 12:07 PM
  2. Correct Syntax
    By bidbud68 in forum Programming
    Replies: 6
    Last Post: 10-19-2012, 01:09 AM
  3. SQL Correct Syntax
    By tbassngal in forum Queries
    Replies: 11
    Last Post: 09-01-2011, 01:55 PM
  4. What is the correct syntax for
    By giladweil in forum Access
    Replies: 1
    Last Post: 07-29-2010, 04:56 AM
  5. Count and recount for every new user per day?
    By valkyry in forum Queries
    Replies: 0
    Last Post: 07-24-2006, 03:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums