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.
Related
I have an Access database that connects to a program's tables via odbc. Is there a way to set refresh intervals in Access so that I don't have to do it manually?
I'd recommend using a timer event:
Edit the (sub)form, select the form object.
On the property sheet, under events set the Timer Interval to 60000 (it's in milliseconds)
in the On Timer event, add an event that does a:
Me.Refresh
I'd probably wrap it in an if statement to stop it messing up edits:
If Not Me.Dirty Then
Me.Refresh
End If
If you have other controls on the sub-form that source data from tables that may change (like combo-boxes that list products, where someone may add a new product) you probably want to use a Me.Requery rather than a simple refresh.
lastly, if the flashing of the screen during updating is a problem, look at:
Application.Echo = False ' turn screen refreshing off
Me.Refresh
Application.Echo = True ' turn refreshing back on
I've been using Application.forms.Count to measure the number of forms that are open, and most of the time, this function works correctly. However, every once in a while, the count is wrong.
When I view the amount in a MsgBox, Access thinks that there are 2 forms open when it is obvious that only 1 is open. I have this running on my Form_Unload method, as the form should only close if it is the last form still open. I have made sure that there are no other instances of Access running when this is performed and no pop-ups or modals are open.
Dim Form As Double
Form = Application.forms.Count
MsgBox Form
If Form = 1 Then
'Nothing, form closes
DoCmd.ShowToolbar "Ribbon", acToolbarYes
Else
MsgBox "You cannot close this form right now."
cancel = True
End If
End Sub
As mentioned, this code does work most of the time, but it is a major hindrance when the wrong count occurs, and I'd like to find out what is causing it.
Using (Debug.Print Forms(0).Name and Debug.Print Forms(1).Name), I was able to figure out that the form I had open had somehow duplicated itself (though only one version of the form is open on the screen). While I have no idea how this happened, a simple restart of MS Access will get rid of the duplication. I'll add this supplemental if statement to prevent this in the future:
If formCount = 1 Then
...
Else
If Forms(0).Name = Forms(1).Name Then
'The duplication error is happening again
DoCmd.Close "FormNameHere"
End If
End If
After all this time, I believe I've found the root of this error. I did not previously know that forms could be opened in the background without actually appearing, and this happens when you read or write a project-level variable. I had checked on a variable and then tried to check the number of forms up, and there was two open despite only one being visible. I think a simple DoCmd.Close "formNameHere" after checking on the variable would be the best way to go about this problem.
I ran the following code On Lost Focus event in Access 2010 with no problems.
Dim strSpell
strSpell = txtMyField
If IsNull(Len(strSpell)) Or Len(strSpell) = 0 Then
Exit Sub
End If
With txtMyField
.SetFocus
.SelStart = 0
.SelLength = Len(strSpell)
End With
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
After upgrading to O365 (Access 2016), the spell check works with no problems unless there's multiple spelling corrections. If the user choose to Change All or change more than 1 word Access crash and the user need to restart the program. I tried to change the code to run On Exit event but it didn't help. I also decompile the database and found no erros.
The only way I can run spell check is using the spell check on the ribbon. I hide the ribbon to prevent the users from messing around so this option is not going to work. Also, I would like to limit spell check to one field and force it after the user exit the field.
I'm guessing that Access is crashing because more than one correction trigger the event again and since spell Check is already running the program crash. Any idea how to fix it ?
UPDATED NOTES FROM COMMENTS
In my testing I found that when you hit Enter several time when you
type in the field, it cause the program to crash.
Text field is LONG TEXT
Form field is bound to text field
I was able to repeat the hanging process "Not Responding" message with a Long Text field and 3500 characters and LOTS of items with 'spelling errors`.
Using your code it would crash with LostFocus code or even if I put it in a command button.
I started wondering if it was the whole text selection that was causing an error with how the spell checker tried to do its job - and whether that was even needed.
When I moved your code out of the LostFocus event and replaced it with this code in the Exit event it worked reliably
EDIT: Moved code to Exit event and specified specific textfield
Private Sub txtMyField_Exit(Cancel As Integer)
With txtMyField
'If the textbox has data run the Spell Checker
If Len(.Value & "") > 0 Then
.SetFocus
.SelStart = 0
.SelLength = Len(.Value)
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True
.SelLength = 0
End If
End With
End Sub
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.
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