PDA

View Full Version : Unable to disable screen updates



Movian
11-05-2013, 11:29 AM
Hi,
I have a new button that needs to run several tasks automaticaly to assist our clients and speed up switching on forms. As such i have made some adjustements to the process, the process works perfectly HOWEVER I am trying to prevent the user seeing the current form being closed another form being made visible from invisible, that form being updated to a new record, that form being made invisible and finaly another form opening up.

I have tried all 3 methods i could find for disabling screen updating, however every single time I run this process I can see all the steps being run through as if the code to disable the echo's wasn't even there.

Any thoughts or help would be apriciated.


If FilterFromCheckout = True Then
On Error Resume Next
Forms("frmMain").Painting = False
Forms("Checkout").Painting = False
Me.Painting = False
On Error GoTo 0

Application.Echo False
DoCmd.Echo False
Forms("Checkout").Command34_Click
End If


Dim myrs As New ADODB.Recordset
myrs.Open "SELECT LargeData from settings", CurrentProject.Connection, adOpenKeyset, adLockReadOnly


If myrs("LargeData") = False Then
If Not IsNull(Me.PatList.Value) Then
searchstring = Me.PatList.Value
DoCmd.Close acForm, "Search"
On Error Resume Next
Forms("frmMain").MedicalID.SetFocus
DoCmd.FindRecord searchstring, acEntire, , acSearchAll, , acCurrent
Forms("BatchPayment").LocatePatient searchstring
On Error GoTo 0
End If
Else
Forms("frmMain").RecordSource = "SELECT * FROM tblPatient WHERE [MedicalID#] = '" & Me.PatList.Value & "'"
DoCmd.Close acForm, "Search"
'Forms("frmMain").Requery
End If


myrs.Close
Set myrs = Nothing

If FilterFromCheckout = True Then
Forms("frmMain").EPMSwitch_Click
DoCmd.Echo True
Application.Echo True
On Error Resume Next
Forms("frmMain").Painting = True
Forms("Checkout").Painting = True
Me.Painting = True
On Error GoTo 0
End If

SoftwareMatt
11-06-2013, 04:36 AM
The Docmd.Echo is all you should need so maybe some of the other stuff is getting in the way.
Try stripping all the other paint and echo commands out and just set DoCmd.Echo False on the first line.

NB: Whenever using Docmd.Echo I always switch it back on in after an error trap to avoid leaving it switched on. Something like this:


On Error GoTo Err_ErrorHandler
DoCmd.Echo False

'ALL OTHER CODE HERE...
Exit_ErrorHandler:
DoCmd.Echo True
Exit Sub
Err_ErrorHandler:
MsgBox Err.Description
Resume Exit_ErrorHandler

SamT
11-06-2013, 05:45 AM
Forms("Checkout").Command34_Click :
Move the operative code from that sub to another and call it with Command34_Click, Then in the "If FilterFromCheckout = True Then " statement just call the other sub.

Forms("Checkout") Code
Sub Operative34()
'Do stuff here
End Sub

Sub Command34_Click()
Operative34
End Sub


If FilterFromCheckout = True Then
'
'
'
Forms("Checkout").Operative34
End IfRepeat Above process as needed.

"Forms("frmMain").MedicalID.SetFocus" will show Forms("frmMain." there is no need to set the focus to retrieve its value.

Movian
11-06-2013, 08:33 AM
Ok perhaps there is an easier way to do this.

I have altered my subs as suggested, however the problem still persists.

SamT - I don't set the focus to get the value, i set the focus to make sure the system is doing the docmd.findrecord correctly, and that is where the problem appears to be. The docmd.findrecord does not appear to run correctly if the frmMain is invisible, thats why i was trying to disable screen updates, make it visible, then find the record, then make it invisible again in the background.

Other than redesigning the functionality of the record set to how i know it SHOULD be (using a complete SQL query to find the single record currently needed) is there a way to do the docmd.findrecord while the form is visible = false ? That would allow me to achieve the same result i am trying to achieve here.

Thanks for the help so far!


Private Sub PatList_DblClick(Cancel As Integer)On Error GoTo Err_ErrorHandler
DoCmd.Echo False
If FilterFromCheckout = True Then
Forms("Checkout").ReturnToFrmMain
End If


ProcessSearch

If FilterFromCheckout = True Then
Forms("frmMain").EPMSwitch_Click
End If


Exit_ErrorHandler:
DoCmd.Echo True
Exit Sub
Err_ErrorHandler:
MsgBox Err.Description
Resume Exit_ErrorHandler
End Sub


Private Sub ProcessSearch()
Dim myrs As New ADODB.Recordset
myrs.Open "SELECT LargeData from settings", CurrentProject.Connection, adOpenKeyset, adLockReadOnly


If myrs("LargeData") = False Then
If Not IsNull(Me.PatList.Value) Then
searchstring = Me.PatList.Value
DoCmd.Close acForm, "Search"
On Error Resume Next
Forms("frmMain").MedicalID.SetFocus
DoCmd.FindRecord searchstring, acEntire, , acSearchAll, , acCurrent
Forms("BatchPayment").LocatePatient searchstring
On Error GoTo 0
End If
Else
Forms("frmMain").RecordSource = "SELECT * FROM tblPatient WHERE [MedicalID#] = '" & Me.PatList.Value & "'"
DoCmd.Close acForm, "Search"
'Forms("frmMain").Requery
End If


myrs.Close
Set myrs = Nothing
End Sub

SoftwareMatt
11-06-2013, 09:06 AM
...is there a way to do the docmd.findrecord while the form is visible = false ? That would allow me to achieve the same result i am trying to achieve here.

The following will do a find but I don't know if it will work if the form is not visible.


With Forms!FormName.Form.RecordsetClone
.FindFirst "[ID] = " & Value
If Not .NoMatch Then
Forms!FormName.FormBookmark = .Bookmark
End If
End With

NB: you will need to change FormName to the actual name of the form you are trying to find on and the findfirst will need to be amended with the exact criteria you need.

SamT
11-06-2013, 06:13 PM
That is a lot of spaghetti code, where one form is calling subs and clicking command buttons on several other Foms, even directing those Forms to do things to yet other Forms. :crying:

Also, I had to assume that "FilterFromCheckout" is a global variable that is set by many different processes, and that it is set/reset after the ProcessSearch sub is run.

Since ProcessSearch is only concerned with frmMain, I suggest moving it to frmMain and just passing the SearchString to it in the PatList Sub.

NOTE: I do NOT understand your code's program flow, so all this is only a suggestion!

frmX code 'Unknown Form name

Private Sub PatList_DblClick(Cancel As Integer)

On Error Goto Err_ErrorHandler
DoCmd.Echo False

'I don't understand your Forms well enough to make a recommendation here
If FilterFromCheckout = True Then
Forms("Checkout").ReturnToFrmMain 'This line looks really really dangerous, processing two Forms at once.
End If


frmMain.ProcessSearch Me.PatList.Value


Exit_ErrorHandler:
DoCmd.Echo True
Exit Sub
Err_ErrorHandler:
MsgBox Err.Description
Resume Exit_ErrorHandler
End Sub


frmMain Code

Sub ProcessSearch(SearchString As String)
Dim myrs As New ADODB.Recordset
myrs.Open "SELECT LargeData from settings", CurrentProject.Connection, adOpenKeyset, adLockReadOnly


If myrs("LargeData") = True Then
Me.RecordSource = "SELECT * FROM tblPatient WHERE [MedicalID#] = '" & SearchString & "'"
DoCmd.Close acForm, "Search"
Else
If searchstring <> "" Then
DoCmd.Close acForm, "Search"
On Error Resume Next

DoCmd.FindRecord searchstring, acEntire, , acSearchAll, , acCurrent

'Can you move the call to the EPMSwitch code to here?

Forms("BatchPayment").LocatePatient searchstring
On Error Goto 0
End If
End If


myrs.Close
Set myrs = Nothing

If FilterFromCheckout = True Then
Me.EPMSwitch_Click 'Consider moving EPMSwitch Code to an "operative" Sub and calling that Sub here.
End If

End Sub

Finally: Every coder reaches a moment when they realize that if they had to do all over again, they would use what they learned in the first go around to do a much better job. The good ones start over.