How i can stop users running MDB file from another location?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aaitaman Tamang
    New Member
    • Jul 2011
    • 22

    How i can stop users running MDB file from another location?

    All,

    I have MDB which located in network drive, sometime user seems to be copy from drive and pasting in desktop. As i have faced the problem earlier i would like to stop the MDB running from another location now. Any VBA to specifying the path where user can't run MDB from another location. Is there any VBA to fix this problem? Any prompt reply huge appreciated


    Thanks,
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    CurrentDb.Name gives the full path name of the open database. When the database opens you simply check this value against what you know to be valid and if found not to be so, just close the database (or exit Access) with a warning message.

    Comment

    • Aaitaman Tamang
      New Member
      • Jul 2011
      • 22

      #3
      NeoPa,

      Thanks a lot. I have resolved this problems. The following are codes i have used and working fine

      Code:
      Dim DP As Variant
      Set DP = CurrentDb
      If DP.Name = "C:\Documents and Settings\ATAMANG\My Documents\DiasblePath.mdb" Then
      
      Else
      MsgBox "You are not in the original source. Please ask your Database admin for help"
      DoCmd.Quit
      End If
      Thanks,

      ** Edit **
      New question can now be found at How do I Disable or Dim Sub-Menu Items Based on UserName.
      Please post in separate threads in future.
      Last edited by NeoPa; Oct 29 '11, 02:35 PM. Reason: Added mandatory [CODE] tags for you and split new question into separate thread.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        I'm afraid you haven't tested that very well. That logic is flawed in multiple ways. Not least because other users would not typically have access to the file if it's saved within your profile (as it seems to be).

        The first thing you need to do is to move it somewhere generally accessible. If it's on a network then it's the network address you need to check, and maybe an extra check if your PC is sharing it as you would not then typically be using the network version of the address even if you were accessing the same database.

        The following code can be considered as a template. It won't work as it stands as I have far too little information to work with :

        Code:
        Private Const conMDBName As String = "DisablePath.mdb"
        Private Const conLocal As String = "C:\LocalPath\" & conMDBName
        Private Const conNetwork As String = "\\Server\Share\NetworkPath\" & conMDBName
        
        Private Sub Form_Open(Cancel As Integer)
            Dim DP As DAO.Database
        
            Set DP = CurrentDb
            If DP.Name = conLocal Or DP.Name = conNetwork Then Exit Sub
            Call MsgBox("You are not in the original source.  " & _
                        "Please ask your Database admin for help")
            Call DoCmd.Quit
        End Sub

        Comment

        Working...