Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52

    Why is window "Macro" shown when I try to run a simple code?

    When trying a very basic thing taken from "Access 2013 Programming from examples..." something unexpected happens. This is the code:
    Code:
     Sub ShowMessage()
        MsgBox "This is a message box in VBA."
    End Sub
    Really basic. When executed a msgbox should be shown: This is a message box in VBA. Instead a window named "Macro" is shown, and there is the name of the macro, and if I push the button"run" the code is run and the Messagebox is shown. But according to the instructions, this "Macro" window should not show up and interfere. What can be wrong?

    Also, if I try to enter more code (more subs) this Macro window comes back when I try to execute, and then I cannot only choose the first subroutine!
    Same question again: What can be wrong?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Where are you calling the Sub from?
    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
    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
    And how?

    Quote Originally Posted by magnusstefan
    Instead a window named "Macro" is shown, and there is the name of the macro
    What is the name of the 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
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52

    I try to explain with a print screen...

    June7 and Missinglinq: This is how the situation looks:
    Click image for larger version. 

Name:	VBA-problem.jpg 
Views:	21 
Size:	111.3 KB 
ID:	22599

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    I just did a test trying to replicate the issue. Can't. MsgBox opens just fine.

    However, the treelist in the Projects pane seems to be missing some lines. Here is what mine looks like.

    Note the Modules folder icon and module listed below it.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    Attached Thumbnails Attached Thumbnails Treelist.JPG  
    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.

  6. #6
    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
    That link craps out, June7...saying that it is an invalid attachement.

    Once again, magnusstefan, exactly how and from where are you calling the Sub?

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

    All posts/responses based on Access 2003/2007

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Interesting, just opened for me. It was supposed to be embedded not a link. Will try to fix.

    Looks like they are calling sub from immediate window for testing.
    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.

  8. #8
    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
    I wondered if the OP was calling it by typing ShowMessage in an Event, like maybe the OnClick event, in the Properties Pane. That might fool the Access Gnomes into thinking that ShowMessage was 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

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Just tested for that. All I get is an error message "cannot find the object", not the Macro dialog.

    Oh, and I just noticed the Immediate window shows different procedure from the Macro dialog popup.

    Think we need the db to figure this one out.
    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.

  10. #10
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Make sure that you do not have a macro with the same name.

    Also try:

    Code:
    Call ShowMessage2 "I am learning VBA"
    and

    Code:
    Call ShowMessage2("I am learning VBA")

    TIP: Add the line Option Explicit after the line Option Database...

  11. #11
    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
    Of course, there's always the possibility that corruption is involved, here!

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

    All posts/responses based on Access 2003/2007

  12. #12
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52
    Chap01.accdb This is the actual database!

    Further explanation: This is the first exercise in the book "Microsoft Access 2013 programming with examples", and the screen shot in the book looks exactly as in my practicefile. You see, the only thing "done" with this database is:
    1) Creating it as a blank database called "Chap01".
    2) Selecting the database Tools tab clicking on "Visual basic."
    3) Inserting a standard module by choosing "module" from the insert menu.
    4) Entering the code.

    The first code works just fine (Sub ShowMessage()
    MsgBox "This is a message box in VBA."
    End Sub)

    But not the second (Sub ShowMessage2(strMessage)
    MsgBox strMessage
    End Sub)
    if tried, the mysterious "Macro window" is suddenly there...

  13. #13
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52
    "Once again, magnusstefan, exactly how and from where are you calling the Sub?"

    Please look at screen shot in post number 4!

    If that does not answer your question, please explain further what information you want!

  14. #14
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52
    Sorry, I just do not understand your answer!

    "Make sure that you do not have a macro with the same name."
    With the same name, as what?!

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Don't want macro to have same name as VBA procedure.

    Since there are no forms or reports, the only place to call from is another Modul1 procedure or the immediate window. Calling both subs from immediate window works just fine.

    So why does your image have ShowMessage2 in the immediate window but the macro popup is for ShowMessage?

    Where exactly are you calling ShowMessage that provokes the popup? If you are trying to reference the sub in a Macro, then be aware macro cannot call Sub, only Function. Change the procedure to a Function. And when you call it, don't forget the ().

    ShowMessage()

    However, since there are no macros in the posted db, still can't explain why you get the macro popup.
    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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  2. Replies: 3
    Last Post: 02-06-2015, 03:22 PM
  3. Replies: 4
    Last Post: 07-12-2014, 02:02 PM
  4. Replies: 0
    Last Post: 01-11-2012, 12:34 PM

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