I want to know how to make this that i have a DB and want to make it in this way that if someone copy it and paste at new system (PC) then it do not work as internally it should be specified with user/machine name in user table in this way i want to restrict copy of the DB unless authorised
I want to know how to make this that i have a DB and want to make it in this way that if someone copy it and paste at new system (PC) then it do not work as internally it should be specified with user/machine name in user table in this way i want to restrict copy of the DB unless authorised
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.
Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.
Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.
Find out your own machine name.
Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
Click on Start Menu.
Type cmd in the 'Search Program and files' control and press Enter.
Type Set in the DOS prompt window.
You will find the Environment setting listed on the window.
Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
USER-PC is my machine's name given as an example.
Note down your machine name and then type Exit to close the DOS command window.
Open Access and create a new Database.
Press ALT+F11 to open the VBA Window.
Select Module from Insert menu and create a new Module.
Copy and Paste the following Code into the Module:
Code:
Function SetBypassProperty()
Const DB_Boolean As Long = 1
ChangeProperty "AllowBypassKey", DB_Boolean, False
CheckMachine
End Function
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")
If strMachine = "USER-PC" Then
'MsgBox "Authorized"
Else
MsgBox "Not Authorized"
DoCmd.Quit
End If
End Function
Replace USER-PC in the Code with your own machine name.
NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
Select databasename Properties (like db3 Properties) from Tools Menu.
Select Protection Tab.
Put check mark in the Lock Project from Viewing
Put a password and verify it in the second control.
Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
Click OK to save and close the control.
Open a new macro and select RunCode in the Action column.
Type SetBypassProperty() in the Function Name argument.
Save the Macro with the name Autoexec
Save and Close the Database.
Open the database and check whether the database is opening normally on your Machine.
Make a copy of the database and take it to another machine and try opening it on that machine.
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.
Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.
Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.
Find out your own machine name.
Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
Click on Start Menu.
Type cmd in the 'Search Program and files' control and press Enter.
Type Set in the DOS prompt window.
You will find the Environment setting listed on the window.
Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
USER-PC is my machine's name given as an example.
Note down your machine name and then type Exit to close the DOS command window.
Open Access and create a new Database.
Press ALT+F11 to open the VBA Window.
Select Module from Insert menu and create a new Module.
Copy and Paste the following Code into the Module:
Code:
Function SetBypassProperty()
Const DB_Boolean As Long = 1
ChangeProperty "AllowBypassKey", DB_Boolean, False
CheckMachine
End Function
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")
If strMachine = "USER-PC" Then
'MsgBox "Authorized"
Else
MsgBox "Not Authorized"
DoCmd.Quit
End If
End Function
Replace USER-PC in the Code with your own machine name.
NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
Select databasename Properties (like db3 Properties) from Tools Menu.
Select Protection Tab.
Put check mark in the Lock Project from Viewing
Put a password and verify it in the second control.
Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
Click OK to save and close the control.
Open a new macro and select RunCode in the Action column.
Type SetBypassProperty() in the Function Name argument.
Save the Macro with the name Autoexec
Save and Close the Database.
Open the database and check whether the database is opening normally on your Machine.
Make a copy of the database and take it to another machine and try opening it on that machine.
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.
Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.
Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.
Find out your own machine name.
Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
Click on Start Menu.
Type cmd in the 'Search Program and files' control and press Enter.
Type Set in the DOS prompt window.
You will find the Environment setting listed on the window.
Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
USER-PC is my machine's name given as an example.
Note down your machine name and then type Exit to close the DOS command window.
Open Access and create a new Database.
Press ALT+F11 to open the VBA Window.
Select Module from Insert menu and create a new Module.
Copy and Paste the following Code into the Module:
Code:
Function SetBypassProperty()
Const DB_Boolean As Long = 1
ChangeProperty "AllowBypassKey", DB_Boolean, False
CheckMachine
End Function
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")
If strMachine = "USER-PC" Then
'MsgBox "Authorized"
Else
MsgBox "Not Authorized"
DoCmd.Quit
End If
End Function
Replace USER-PC in the Code with your own machine name.
NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
Select databasename Properties (like db3 Properties) from Tools Menu.
Select Protection Tab.
Put check mark in the Lock Project from Viewing
Put a password and verify it in the second control.
Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
Click OK to save and close the control.
Open a new macro and select RunCode in the Action column.
Type SetBypassProperty() in the Function Name argument.
Save the Macro with the name Autoexec
Save and Close the Database.
Open the database and check whether the database is opening normally on your Machine.
Make a copy of the database and take it to another machine and try opening it on that machine.
As far as module as concern it is clear to me but how to locate it as you mentioned in the quote but i ma not finding the fields you mentioned kindly if you brief in details that how to locate this module and the fields as me not very much famiiliar with the fields
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.
Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.
Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.
Find out your own machine name.
Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
Click on Start Menu.
Type cmd in the 'Search Program and files' control and press Enter.
Type Set in the DOS prompt window.
You will find the Environment setting listed on the window.
Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
USER-PC is my machine's name given as an example.
Note down your machine name and then type Exit to close the DOS command window.
Open Access and create a new Database.
Press ALT+F11 to open the VBA Window.
Select Module from Insert menu and create a new Module.
Copy and Paste the following Code into the Module:
Code:
Function SetBypassProperty()
Const DB_Boolean As Long = 1
ChangeProperty "AllowBypassKey", DB_Boolean, False
CheckMachine
End Function
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")
If strMachine = "USER-PC" Then
'MsgBox "Authorized"
Else
MsgBox "Not Authorized"
DoCmd.Quit
End If
End Function
Replace USER-PC in the Code with your own machine name.
NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
Select databasename Properties (like db3 Properties) from Tools Menu.
Select Protection Tab.
Put check mark in the Lock Project from Viewing
Put a password and verify it in the second control.
Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
Click OK to save and close the control.
Open a new macro and select RunCode in the Action column.
Type SetBypassProperty() in the Function Name argument.
Save the Macro with the name Autoexec
Save and Close the Database.
Open the database and check whether the database is opening normally on your Machine.
Make a copy of the database and take it to another machine and try opening it on that machine.
I have done as instructed but even after changing the user-pc by my machine name then other name which is not my machine name the db still opening and not closing it self, when i double click autoexe macro it saying not authorized and when i click module then it is asking for password i thin these things are working fine but there might be some other error
Bunch of Thanks for the sample and your time.. please advise how to open the file as currently is opening with a message saying not authorised and closing thereafter.. i know it is working correct but wanted to know the tips to change the module enviornment name
@Apr Pillai
I use a piece of code like yours, founded somewhere on the web with an .accdb database (Access 2007).
All is fine IF the DB is in a trusted folder. As soon as I move the DB in other location (not "trusted") my work is go to hell because no code is allowed to run (including this one).
@syedadnan
Apr Pillai wrote:
Put a password and verify it in the second control.
Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.
Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.
Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.
Find out your own machine name.
Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
Click on Start Menu.
Type cmd in the 'Search Program and files' control and press Enter.
Type Set in the DOS prompt window.
You will find the Environment setting listed on the window.
Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
USER-PC is my machine's name given as an example.
Note down your machine name and then type Exit to close the DOS command window.
Open Access and create a new Database.
Press ALT+F11 to open the VBA Window.
Select Module from Insert menu and create a new Module.
Copy and Paste the following Code into the Module:
Code:
Function SetBypassProperty()
Const DB_Boolean As Long = 1
ChangeProperty "AllowBypassKey", DB_Boolean, False
CheckMachine
End Function
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")
If strMachine = "USER-PC" Then
'MsgBox "Authorized"
Else
MsgBox "Not Authorized"
DoCmd.Quit
End If
End Function
Replace USER-PC in the Code with your own machine name.
NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
Select databasename Properties (like db3 Properties) from Tools Menu.
Select Protection Tab.
Put check mark in the Lock Project from Viewing
Put a password and verify it in the second control.
Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
Click OK to save and close the control.
Open a new macro and select RunCode in the Action column.
Type SetBypassProperty() in the Function Name argument.
Save the Macro with the name Autoexec
Save and Close the Database.
Open the database and check whether the database is opening normally on your Machine.
Make a copy of the database and take it to another machine and try opening it on that machine.
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")
Select Case strMachine
Case "USER-PC", "ABC-PC", "ZYX-PC"
'Authorized
Case Else
MsgBox "Not Authorized"
DoCmd.Quit
End Select
End Function
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")
Select Case strMachine
Case "USER-PC", "ABC-PC", "ZYX-PC"
'Authorized
Case Else
MsgBox "Not Authorized"
DoCmd.Quit
End Select
End Function
@synedadnan - Please could you refrain from quoting the entire previous text in your replies - it make the threads unnecessarily long and difficult to read. Simply trim out all the quoted text except what is relevant to your response.