Results 1 to 10 of 10
  1. #1
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142

    vba to macro

    I am creating a customized ribbon and have figured out the code to include buttons to click, the option is to run a macro.
    My question is can I convert the code below into a macro?

    Private Sub ExtBtn_Click()
    Msg = "Are you sure you want to close the database?"
    Style = vbYesNo + vbCritical + vbDefaultButton2
    Title = "You Are Closing The Database"
    Response = MsgBox(Msg, Style, Title)


    If Response = vbYes Then
    MyString = "Yes"
    DoCmd.Quit acQuitSaveAll
    Else
    MyString = "No"
    DoCmd.CancelEvent
    End If
    End Sub

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi, you can run the code from a macro action RunCode if you wrap it in a public function.

  3. #3
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    Thanks, not sure I am doing what you suggest I tried creating a module no success, a class module no success.
    I entered the following code:
    Public Sub RunMacro()
    Msg = "Are you sure you want to close the database?"
    Style = vbYesNo + vbCritical + vbDefaultButton2
    Title = "You Are Closing The Database"
    Response = MsgBox(Msg, Style, Title)
    If Response = vbYes Then
    MyString = "Yes"
    DoCmd.Quit acQuitSaveAll
    Else
    MyString = "No"
    DoCmd.CancelEvent
    End If
    End Sub

    My XML code looks like below:
    <button id="Exit" size="large" label="EXIT" imageMso="FileCloseDatabase" onAction="Module1" />
    Both say they cant recognize the module??

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I would not use macro. I put code in a VBA general module.

    The XML would reference the procedure, not the module: onAction="RunMacro".
    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
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    Tried this and got the error message below:
    Cannot runthe macro or callback function ‘RunMacro’.
    Make surethe macro or function exists and takes the correct parameters.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You might want to rename the procedure from "Runmacro" to "RunMyMacro".

    "Runmacro" is a member of the "Docmd" object.

    Just a thought........

  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,929
    Exactly where is the XML code?
    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
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    I got the same error message.

    XML code is in a table USysRibbons

  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,929
    All I can say is code works in my db. If you want to provide yours for analysis, follow instructions at bottom of my post.

    Did you get your code sample from http://www.accessribbon.de/en/?Acces...ton_-_onAction
    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
    Derrick T. Davidson is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    142
    Started again fro start of this post and for some reason it works now?????
    Thanks for all your help

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

Similar Threads

  1. Command Button to Run Macro, can't find macro
    By Ace2014 in forum Modules
    Replies: 22
    Last Post: 06-11-2014, 11:42 AM
  2. Replies: 2
    Last Post: 06-30-2013, 09:59 AM
  3. Replies: 2
    Last Post: 05-05-2012, 02:34 AM
  4. Macro help
    By jcaptchaos2 in forum Access
    Replies: 2
    Last Post: 05-04-2011, 09:50 AM
  5. Replies: 0
    Last Post: 01-12-2011, 12:43 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