I use a form to run a few codes on a database in Access. During update or deletion Access asks whether you want to update or delete.
I would like to know if there is any way of turning off these system messages or let the user choose his preference on whether he would like thoses messages to pop up or not.
Don't foget to turn these back on.
DoCmd.SetWarnings false
DoCmd.SetWarnings true
Application.DisplayAlerts = false
Application.DisplayAlerts = true
Related
How to stop screen updating in access ?
For Each Button "me.painting = false "didn't work
Note :- the form have a lot of Buttons :D
Application.Echo False
' complicated code
Application.Echo True
Be sure that Application.Echo True is always reached - if it is skipped e.g. due to a runtime error, your users will have to kill Access via Task Manager.
Access Docment scanned with Macfee and Microsoft on a server platform One drive so completly safe.
I want a user login page which has different levels so that different users will have access to different objects or functionality.
Please have a look at the coding below I have also attached a link to onedrive for the access 2013 document.
code:
Private Sub Form_Load()
Dim Security As Integer
Me.txtLogin = Environ(“userName”)
Me.txtUser = DLookup(“userName”, “tblUser”, “Username = ‘” & User & “‘”)Then
If IsNull(DLookup(“userSecurity”, “tblUser”, “UserLogin = ‘” & Me.txtLogin & “‘”)) Then
MsgBox (“No User security set up for this user. Please contact the Admin”, vbOKOnly, “Login Info”
Me.NavigationButton13.Enabled = False
Else
Security = DLookup(“userSecurity”, “tblUser”, “UserLogin = ‘” & Me.txtLogin & “‘”)
If Security = 1 Then
Me.NavigationButton15.Enabled = True
Else
Me.NavigationButton15.Enabled = False
End If
End If
End Sub
I am guessing you have a main login page for the entire app, which is the startup form. Keep in mind that a user can hold down the Shift key when opening your app to bypass any startup code, but you can disable that. You can also hide the database container. Users can always use another DB to link your tables, or import objects, so you will also want to lock the entire database with a password.
The form startup code can check your custom security table and then you can use Cancel = True to short-circuit the opening event. It seems like you are trying to accomplish that by disabling navigation buttons, but you may want to disallow the opening of the form.
As HansUp and Tim have suggested, tt would be helpful if you can describe your situation a bit more so that we can respond more concisely. If you have a situation where you need true security that is hard to breech, you may want to consider moving your tables into SQL Server (or SQL Express) and linking them to your Access container. Ultimately, there's nothing you can do in Access that I could not get around.
I am using Microsoft Access 2013 to create a database where I have a form that the default view is read-only to prevent accidental editing. I am currently trying to include a button to enable editing for the current record only. I tried using DoCmd.OpenForm to open the record in editable mode (since I am using that command elsewhere to open specific records), but it seems like it can not open a record within the same form with that command.
I thank you in advance for any advice on how to solve this issue.
You cannot edit anything else than the current record.
Use this code line:
Me.AllowEditions = True
But it doesn't make much sense as you could just open the form this way.
I learned this from the first VBA book I ever read (Access 97 VBA for Dummies, I think), and I have never seen anyone use the Tag property since, which has no other purpose than for you to find something to use it for. Enter "Lockable" in the tag property for any control (text box, combobox etc.) that you want to protect. Add a button named btnEdit to your form.
When you enter a record, the Form Current event will unlock the controls if it is a new record, and lock the controls if it is an existing record.
The button will then unlock to allow edits, and re-lock once the record is exited. I've found this to be very effective in preventing inadvertent edits.
Private Sub Form_Current()
Dim ctlCurr As Control
'Lock the record if it is not new. Prevents inadvertent edits.
If Me.NewRecord = False Then
For Each ctlCurr In Me.Controls
If ctlCurr.Tag = "Lockable" Then
ctlCurr.Locked = True
End If
btnEdit.Enabled = True
Next
End If
'Unlock a new record for editing.
If Me.NewRecord = True Then
For Each ctlCurr In Me.Controls
If ctlCurr.Tag = "Lockable" Then
ctlCurr.Locked = False
End If
Next
btnEdit.Enabled = False
End If
End Sub
Private Sub btnEdit_Click()
Dim ctlCurr As Control
'Unlocks a record for editing. Requires the operator to make the decision to edit.
If Me.NewRecord = False Then
For Each ctlCurr In Me.Controls
If ctlCurr.Tag = "Lockable" Then
ctlCurr.Locked = False
End If
Next
End If
End Sub
I'm building a front end for an Access database. My users don't want or need to see the "You about to insert X records" sort of messages that come up when you run an INSERT, UPDATE or DELETE query.
The only way I've been able to find to turn these messages off programtically is DoCmd.SetWarnings False in VBA and then turning them on afterwards. However, this disables all warnings, and if the code errors before the DoCmd.SetWarnings True command, then they stay off, which can be anything from a nuisance to dangerous.
Is there any way of supressing only the SQL warnings in Access and leaving others (e.g. the "do you want to save this query" messages) intact?
Run "action queries" with Database.Execute or QueryDef.Execute instead of DoCmd.RunSQL.
The .Execute methods do not trigger those confirmation messages, so no motivation to use SetWarnings False to suppress them.
There is also this alternative, for those not wanting to write code
In Access Options > Advanced > Uncheck the required confirmation for the desired fields.
I have a process in an MS Access database that the users will usually run once daily, but could be more or less. It takes several minutes and requires temporary exclusive access because it deletes and recreates the main table.
I have code to check to see if there are other users in the db before the process starts, but is there a way to change the access to "exclusive" at the beginning, and then change it back to open access at the end?
Access sets the exclusive/shared mode only when it opens the database. So it's not something you can do "on the fly" unless you have another database that does the open/close.
So you can have a "maintenance" database that does the dropping and recreating of the table in the other database - the maintenance database can open the database in exclusive mode.
BTW - it's probably not good practice to do this - the dropping/recreating the table will increase the size of your database each time and you will need regular compacts to keep the size under control. If possible find a different design that does not require this operation.
If you run Access with the /excl commandline argument, it should open the database in exclusive mode.
But it's not clear to me if you're doing this from Access.
You can use a table and the timer on a hidden form. The timer checks the value on the table in Access database. When the value is set to kick everyone out it kicks everyone one out.
Example code for hidden form:
Private Sub Form_Timer()
'On Error GoTo Err_Handler
Dim fLogout As Boolean
'checks to see if the table is set to false
fLogout = DLookup("on_off", "tblAdminSettings", "Control = 'logoff?'")
If fLogout = True Then
'this is your timer it allows everyone to be logged off
T1 = Now()
T2 = DateAdd("s", 10, T1)
Do Until T2 <= T1
T1 = Now()
Loop
DoCmd.SetWarnings False
DoCmd.Quit
End If
Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error Your Killing me Smalls"
Resume Exit_Here
End Sub
Remember to make sure you have a way to set the value back to false when you open the database other wise it will always close.