Results 1 to 6 of 6
  1. #1
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    348

    Access attempts to run a non existent macro

    I want to move to the Next Record in my Form, then back again. (LOL not for fun, when working I want to do stuff with the next record).
    Getting this to work is proving difficult.

    It's called from the Form Current event. It's a datasheet mode subForm and NoCurrent is a Global Boolean.

    Code:
    Private Sub Form_Current()
        
        If NoCurrent = True Then
            NoCurrent = False
            Exit Sub
        End If
    
    Call Test9
    
    Sub Test9 ()
        NoCurrent = True
            DoCmd.GoToRecord , , acNext
    
           NoCurrent = True
           DoCmd.GoToRecord , , acPrevious
    End Sub

    Access won't let me step through and observe what's going on. You can't use the GoToRecord action or method on an object in Design view.
    What I expect is to stay on the row I click in. This seems to work only once then I get Microsoft Office Access can't find the macro 'True.'
    The macro (or its macro group) doesn't exist, or the macro is new but hasn't been saved.


    I will probably alter this drastically to make it work, but any idea why Access is trying to find a macro that doesn't exist? There are no macros.


    Or ideas for a better logic flow ? Thanks.
    Last edited by Middlemarch; 07-30-2016 at 06:41 PM. Reason: Fixed typo....

  2. #2
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Is this really your code? There is no End Sub for the current event sub.
    If there isn't even an embedded macro (and I'm guessing there isn't based on the name returned (True)) then try a compact and repair in case it's a simple matter of corruption.
    If that doesn't help, since it's a small piece of code, try putting line numbers on each potential line that could be generating the error. It's likely the sub (which seems to have an extra space after '9', but hard to tell for sure in the posted code. Add an error handling routine at the start and msgbox.Erl to get the line number generating the error. It could be that the variable is not as global as you think. Why would this not just be at the module level as opposed to being global in scope. I'm assuming you know the difference between global, module level and form level scope as opposed to procedure level scope.

    Code:
    Private Sub Form_Current()
    On Error GoTo errHandler
    
    10  If NoCurrent = True Then
    20     NoCurrent = False
    30     Exit Sub
    40  End If
    
    50  Call Test9
    60 Exit Sub
    
    errHandler:
    msgbox "Current Event failed on line" & Erl
    
    END SUB
    
    Sub Test9 ()
    
    On Error GoTo errHandler
    10  NoCurrent = True
    20  DoCmd.GoToRecord , , acNext
    
    30  NoCurrent = True
    40  DoCmd.GoToRecord , , acPrevious
    50  Exit Sub
    
    errHandler:
    msgbox "Test 9 failed on line " & Erl
    
    End Sub
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Micron View Post
    ...It could be that the variable is not as global as you think...
    This would be my guess, too. The error message 'Microsoft Office Access can't find the macro 'True'' indicates that the Access Gnomes don't recognize NoCurrent as a Boolean variable...and hence assume that 'True' must be the name of a Macro.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    348
    Thanks for the replies. It now seems to work flawlessly after a C&R and close and reboot Access.
    Micron that's a useful debug method (I didn't know about erl).
    The variable was/is global - declared as Public NoCurrent As Boolean in Module 1. Mainly so I could use it anywhere.
    I probably don't know everything about scope, only that Form is Form only and Module is anywhere. (I hope.)

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    I think you've got the basics for scope. Just to clarify and possibly for the benefit of others:
    - variables declared at the procedure level are only visible to the procedure
    - variables declared at the top of a form or report module (right after Option Explicit, which should ALWAYS be used) are visible to the entire module
    - variables declared in a standard module (one that is not part of a form/report) can be either procedure level or module level or global. To make it global (visible to the entire database), the Public keyword is used. Scope is held to the module or procedure level by making the variable Private. Where you place it in the module can make it private to the module or procedure in much the same way you declare it in a form/report module (if memory serves - which it often doesn't anymore).

    Glad you got it solved.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    348
    Thanks Micron... got it !

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

Similar Threads

  1. Replies: 11
    Last Post: 06-16-2014, 08:52 AM
  2. Replies: 4
    Last Post: 06-08-2014, 11:53 AM
  3. Limit Login Attempts
    By data808 in forum Access
    Replies: 4
    Last Post: 04-02-2014, 02:00 AM
  4. Trying to find hour that has most attempts
    By pdpeterson87 in forum Queries
    Replies: 5
    Last Post: 10-08-2013, 03:52 PM
  5. Form Seach Box-all attempts have failed.
    By leamas in forum Forms
    Replies: 12
    Last Post: 06-07-2012, 09:57 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