Need to make Do loop stop (1 Viewer)

tsteinh

Registered User.
Local time
Today, 16:51
Joined
Jan 12, 2001
Messages
13
I am having some problems with my code and could use some insight. I am waiting for a field in a one-record file to be filled by an outside process. Once this field is filled, I can retrieve the value and continue processing. There are 2 sides on the screen and this code is operating on the right side. Both sides have a 'Close' button that can be used to close out one side or the other. If the user clicks the close button on the side that is waiting for the field to be filled, he is able to do other operations, but sometimes I get an error when the Do loop attempts to check the screen field for a value (when the user closes the side of the form, this field is made invisible, hence the error)

Is there some way to make this loop end when the close button is selected??

Here is the code:
'begin polling for mass value
Do Until txtMass.Value <> 0 ' this is a screen field
DoEvents 'let other stuff happen
Set rs = CurrentDb.OpenRecordset("tblReadings")
If rs("Mass") <> 0 Then 'if field is filled
txtMass.Value = rs("Mass") 'get value
txtNetMass.Value = txtMass.Value - txtTare.Value
rs.Edit
rs!Mass = 0
rs.Update
End If
rs.Close
Loop
 

Alexandre

Registered User.
Local time
Today, 22:51
Joined
Feb 22, 2001
Messages
794
Perhaps I am getting it wrong but my understanding is that you have three controls and would like to update one of them (txtNetMass) using values of the two others (txtMass, txtTare), whenever the content of txtMass is changed (or becomes different form zero). I guess also that txtNetMass and txtTare are not on the same form than txtMass.

Then using the after update event of txtMass you should try:
Dim Frm1, Frm2 as Form
Dim CtlMass, CtlNetMass, CtlTare

Set Frm1 = Forms![NameFormContainingTxtMass]
Set Frm2 = Forms![NameOtherForm]

Set CltMass = Frm1![txtMass]
Set CtlNetMass = Frm2![txtNetMass]
Set CtlTare = Frm2![txtTare]

CtlNetMass.Value = CtlMass.Value - CtlTare.Value
 

tsteinh

Registered User.
Local time
Today, 16:51
Joined
Jan 12, 2001
Messages
13
Let me explain a little better :)

txtMass, txtTare, and txtNetMass are on the same form. txtMass will be updated within the do loop whenever tblReadings (updated from another process, not on this form) Mass field becomes nonzero. The loop is waiting for this event to occur. When it does, the value in the tblReadings.Mass field will be moved into txtMass and txtNetMass will be computed. txtTare is just another field on the screen entered by the user.

The DoEvents is added to this process so that if the user decides to abort the process, he can. However, when he does abort (by clicking the Close button to close out or abort just this process), the close onclick event makes the txtMass field invisible (txtMass.Visible = false). It appears that the do loop is still operating, which makes the error occur because now the txtMass field is not there.

I appreciate your assistance! Does this make the process clearer?

Thanks in advance!
 
T

The L&L Company

Guest
What about...

On Error GoTo FormClosed
...
...
FormClosed:
Exit Sub

Use some type of error handling.

Just my .02

~ Joe
 

Alexandre

Registered User.
Local time
Today, 22:51
Joined
Feb 22, 2001
Messages
794
It does.

I would think in creating a global value acting as a Flag to know when the user is closing the form:

FlagCloseForm as boolean

Using the onclik event of the close button on your form:
FlagOnClose=True

And in your loop after doEvents
If FlagCloseForm = true then exit sub (or goto, etc..)

You must determine when it is the most appropriate to reset your flag to false (on load event of the form perhaps?)


Hope this helps
 

Alexandre

Registered User.
Local time
Today, 22:51
Joined
Feb 22, 2001
Messages
794
L&L proposal is probably better. You can make it more selective if neeede by detemining the value Err takes when the user closes the form, and upon this value decide to resume or not.
 

tsteinh

Registered User.
Local time
Today, 16:51
Joined
Jan 12, 2001
Messages
13
Joe and Alexandre:

Thanks to both of you! I will try both options and see which one works best.

This is the best forum for Access questions that I have found! I spend a lot of time searching for advise here! Keep up the good work!
 

Users who are viewing this thread

Top Bottom