Results 1 to 4 of 4
  1. #1
    Isebrand is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    4

    Not Counting Properly in VBA

    Having a bit of trouble in Access VBA. Using the code portion below I am using VBA to count records in a record set. Essentially I am counting records in a Section named 68 (record type is not a number but short text). The one that I have Dimensioned as K68Over14 works but K68all gives me a Type Mismatch error Run-Time Error '13':

    I feel it is because it is a number but it doesn't make why one would work but one would not when the code is almost exactly the same.


    Dim K68all As String
    Dim K68OVER14 As String


    Does not Work:
    ElseIf MyRs![CAL_AREA_1] = "68" Then
    K68all = K68all +1
    Works:


    ElseIf MyRs![DAYS_IN_LAB] > 14 And MyRs![CAL_AREA_1] = "68" Then
    K68OVER14 = K68OVER14 + 1

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Is this actually the code? This makes no sense:

    K68all = K68all = 1

    if you want to do math with the variables, they should be given a numeric data type.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Isebrand is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    4
    Yea I realized a bit ago I had put that but it still is not working......it should have read K68All=K68All + 1

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Have you tried declaring the variables as Integer? What line exactly errors? The test or the next line?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. VBA Not Iterating Properly
    By jo15765 in forum Programming
    Replies: 7
    Last Post: 03-30-2017, 04:56 PM
  2. Is this relationship set up properly
    By Xterra14s in forum Access
    Replies: 1
    Last Post: 07-20-2016, 06:19 AM
  3. Reports not sorting properly
    By Nick Lingenfelter in forum Reports
    Replies: 10
    Last Post: 02-26-2013, 06:38 PM
  4. Checkboxes not working properly
    By TK03 in forum Access
    Replies: 1
    Last Post: 12-24-2012, 09:04 AM
  5. Cannot split a DB properly
    By Swarland in forum Access
    Replies: 3
    Last Post: 12-17-2010, 04:44 AM

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