Results 1 to 8 of 8
  1. #1
    HoustonIT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    4

    Running exe's or Powershell from an Access form button

    Hello all!



    I am trying to create an inventory DB for us server admins here and would like to have a few buttons on the forms that run various commands. For example, I would like to have a "Ping" button that, you guessed it, pings the server name in the Server Name field. I am not a programmer or scripter by any means, but I'm sure this is a piece of cake to one some of you guys. If someone could help me out, I'd really appreciate it. Thanks in advance!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    You can try something like this using the Shell function
    Code:
    Sub MyPing()
    
    Dim x As String
    x = "www.yahoo.com"
    Shell "ping" & " " & x
    End Sub

  3. #3
    HoustonIT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    4
    Thanks a lot Orange, I've got that code pasted into the Visual Basic area, but I cannot get my button to execute it. When I select the button's OnClick option, I select RunMacro and type the name of the module - MyPing, and it fails. I'm thinking the module needs to be turned into a macro somehow but I am unsure how to do that in Access 2010. Any ideas?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    I don't have acc2010.
    I had a question the other day from someone trying to runs ome code from a Macro.
    I'm not sure where it is at the moment.
    We got it working but we had to make the Sub into a Function in order for the macro to recognize it.
    I'll look for it.

    Found it, but you might try this tutorial to set up your button on a form and use vba

    http://www.bluemoosetech.com/videos/...o.php?VID=vid8

    I noticed when I run MyPing from a button, it opens a cmd window and executes Ping but closes immediately.
    I'm not sure how to keep that window open, if it's necessary.

    But maybe you know how to do that or how to open cmd.exe to open Ping with your address? Powershell??

  5. #5
    HoustonIT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    4
    Great tutorial orange, but 2010 is a different animal. When I select "OnClick", it brings me to the Macro Tools view with @ 20 options, but the ones that stick out the most are the runmacro and rundatamacro. I've typed MyPing into the macro box to run, but it fails with this:

    Access was unable to locate the macro or VBA function. If you are trying to call a macro, make sure that the name of the macro and the name of the macro group are spelled correctly.
    If you are trying to call a user-defined VBA function, be sure to use the following syntax:
    =FunctionName() or =FunctionName(argument1,argument2,...)
    Make sure that the function is either:
    Defined in the code for the form or report.
    - or -
    A public function that is in a module (not a class module).

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Quote Originally Posted by HoustonIT View Post
    Great tutorial orange, but 2010 is a different animal. When I select "OnClick", it brings me to the Macro Tools view with @ 20 options, but the ones that stick out the most are the runmacro and rundatamacro. I've typed MyPing into the macro box to run, but it fails with this:

    Access was unable to locate the macro or VBA function. If you are trying to call a macro, make sure that the name of the macro and the name of the macro group are spelled correctly.
    If you are trying to call a user-defined VBA function, be sure to use the following syntax:
    =FunctionName() or =FunctionName(argument1,argument2,...)
    Make sure that the function is either:
    Defined in the code for the form or report.
    - or -
    A public function that is in a module (not a class module).
    Change this a Sub procedure
    Code:
    Sub MyPing()
    
    Dim x As String
    x = "www.yahoo.com"
    Shell "ping" & " " & x
    End Sub
    to this a Function where
    IPAddr is the address you want to ping. The Address must be within double quotes.
    Code:
    Function MyPing(IPAddr as string)
    If len(IPAddr) >0 Then
      Shell  "ping" & " " & IPAddr
    else
      MsgBox "Bad address was passed ....quitting"
    End If
    End Function
    Glad you like the tutorial.

    Give it a try.
    Last edited by orange; 04-14-2011 at 02:55 PM.

  7. #7
    HoustonIT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    4
    I am still unable to get either one to work . I think with all the security "features" in 2010 they don't want you to be able to run code as easily as you could in XP/2003.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Well I don't have, and have never used acc2010, so I can't advise.


    I just did some more searching with some forums and found an answer.
    Take a look here. http://www.access-programmers.co.uk/...d.php?t=175081

    I used the functions set up by Boyd and I can ping local and yahoo.
    Just a caution: Boyd has 2 functions named SystemOnline.

    I just renamed all occurences of "SystemOnline" in the more eloquent function to "SystemOnline1" to remove naming conflict.

    I know Boyd is on Access World Forums a lot so if you have difficulty, you might try posting on AWF.
    I'm sure if Boyd sees such a post, he will respond.

    CharlesWhiteman has adapted the function to his own forms according to the posts.

    Good luck

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

Similar Threads

  1. Access Form- Save/Close Button error
    By Ashe in forum Forms
    Replies: 3
    Last Post: 02-10-2011, 01:01 PM
  2. Replies: 3
    Last Post: 10-04-2010, 01:31 PM
  3. Submit button in access form
    By Melo in forum Forms
    Replies: 2
    Last Post: 09-25-2010, 08:37 AM
  4. Replies: 1
    Last Post: 04-06-2009, 12:05 PM
  5. Net Send from a button on an Access form
    By Deb4995 in forum Forms
    Replies: 0
    Last Post: 10-19-2006, 10:19 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