Results 1 to 9 of 9
  1. #1
    bastnpak is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2024
    Posts
    12

    auto/quick run of module

    I created a module with working code. I want to create a 'quick run' button so users can just click and go.

    I am going to share the code with my teammates and they are looking for just a 'go' button. Running a macro is OK too (they already do that for a different task).

    I am not using a form. I am looking at tables directly.

    How would I convert this to a macro (that does the quick run)? or is there a better option

  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,521
    Moat of us never let users into tables directly, but if you make your code a public function in a standard module you can run it with a macro and the RunCode action (I think that's what it's called anyway).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bastnpak is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2024
    Posts
    12
    I agree with not letting users go to the code directly. we are the data analysts that work the back end. But most of the others are not proficient coders. so I am writing the code for them to quickly run.

    I tried to do the new macro with the RunCode and then put in the function name (it even finds the name to fill in).

    but I am getting the error "the expression you entered has a function name that microsoft Access can't find"

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by bastnpak View Post
    I agree with not letting users go to the code directly. we are the data analysts that work the back end. But most of the others are not proficient coders. so I am writing the code for them to quickly run.

    I tried to do the new macro with the RunCode and then put in the function name (it even finds the name to fill in).

    but I am getting the error "the expression you entered has a function name that microsoft Access can't find"
    And that function name is? Ist it Public?
    is this a macro?, try VBA, then it would likely tell you.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll get out of the way, but also make sure you include parentheses:

    FunctionName()
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    bastnpak is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2024
    Posts
    12
    I wrote in VBA. I meant it as a macro with a quick launch button. I am used to excel where you write the vba and then run it as a macro. it just returns message boxes.

    but when you select the module, it shows all the code. I was hoping for it to just run the code.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Macroes are something completely different in Access.
    How are you trying to run it?

    Step into it in the code window and run line by line with F8, does that work.

    Failing that, start showing your code.
    I know what you mean with quick launch buttons on the toolbar, I use them in Excel.

    If you want to emulate your Excel method, you would actually need to create an Access Macro and add that to the ribbon. They only run functions, so the VBA would need to be a function, or a function that runs a sub.
    Most people would create some sort of interface, a simple form with command buttons/combos/listboxes to run popular/well used code.

    Need to also stop thinking with an Excel head. Access is a different beast althogether. VBA is similar, but that is about it.

    This is how I used to handle it from a standard Access switchboard
    The button would run a macro which would call perhaps CreateBackupFE()

    Code:
    Function CreateBackupFE()
    ' Have to do it this way as Switchboard does not allow parameters.
    CreateBackup ("FE")
    End Function
    
    Sub CreateBackup(Optional strDBType As String)
        Dim strDBpath As String, ext As String, tmp As String
        Dim strPath As String, strBackupPath As String, strDB As String
        
        
        'tmp = CurrentDb.Name    'or maybe this should be the name of your BE
        'strDBType = "FE"
        strDBpath = GetAccessBE_PathFilename("tblUser")
        strPath = Left(strDBpath, InStrRev(strDBpath, "\"))
        strBackupPath = strPath & "Backup\"
        
        'Will now backup front and back end database
        If strDBType = "FE" Then
            strDBpath = CurrentDb.Name
        End If
        strDB = Right(strDBpath, Len(strDBpath) - InStrRev(strDBpath, "\"))
        
        With CreateObject("Scripting.FileSystemObject")
            'ext = "." & .GetExtensionName(tmp)
            tmp = strBackupPath & Format(Now(), "yyyymmdd_hhnnss") & "_" & strDB
            .CopyFile strDBpath, tmp
        End With
        MsgBox strDBType & " Database saved as " & tmp
        
        
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    You can modify the Access ribbon to simulate the Excel ribbon.

    Click image for larger version. 

Name:	Howto.png 
Views:	12 
Size:	94.7 KB 
ID:	51547

    The result:

    Click image for larger version. 

Name:	Result.png 
Views:	12 
Size:	8.7 KB 
ID:	51548

  9. #9
    bastnpak is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2024
    Posts
    12
    I know I am new to access so still learning the ins and out.

    the use of a function that called the sub was perfect. Since Access allows you to add a command in a new macro of "RunCode", it worked great.

    thank you for all the help

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

Similar Threads

  1. Replies: 4
    Last Post: 08-03-2023, 05:41 PM
  2. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM
  3. auto run Module
    By stu_C in forum Modules
    Replies: 1
    Last Post: 08-01-2011, 06:54 AM
  4. Replies: 4
    Last Post: 05-16-2011, 04:58 PM
  5. Quick Module Question: :)
    By oregoncrete in forum Modules
    Replies: 11
    Last Post: 04-04-2011, 04:42 PM

Tags for this Thread

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