locked
Compile error: Sub or Function not defined RRS feed

  • Question

  • Hi, I'm quite a noob at access and I've recently starting applying vba in a database I've been tasked with to create for my department. 

    I've got this code that I've written that allows users to access a ribbon or specifically a button on a ribbon, and I want it to open the window if the specified user is an admin, however if not then it will come up with a message "Access required". I had an issue that both windows would pop up for both users, so I added "gototheend" (see below) so it would skip part of the code however the moment I add that code in it gives me the error message shown in the title. If anyone could help that would be greatly appreciated thanks!

    my code for reference:

    If GBL_Mode = "Admin" then GoTo Proto

    If GBL_Mode = "User" then GoTo Bravo

    Proto: 

         DoCmd.OpenForm"Usercontrol", acNormal, "", "", , acNormal

         gototheend

    Bravo:

        Msgbox "Access Required"

       End Function


    • Edited by tommm___ Thursday, June 27, 2019 8:30 AM typo
    Thursday, June 27, 2019 8:27 AM

All replies

  • gototheend is not an existing command. You could use Exit Function instead, but I'd structure the code differently:

        Select Case GBL_Mode
            Case "Admin"
                DoCmd.OpenForm "UserControl"
            Case "User"
                MsgBox "Access Required"
        End Select
    End Function


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, June 27, 2019 8:36 AM
  • I've just given it ago, 

    I think it works But It made me realise that I've got another issue with a table somewhere haha, so I'll just go fix that up. 

    Thank you for the help!

    Thursday, June 27, 2019 9:53 AM