Using an Option Group to control a Loop produces error

GKIL67

Registered User.
Local time
Today, 20:51
Joined
Apr 28, 2011
Messages
24
I have a form with unbound fields and using an option group (gStartStop) with two buttons, Start/Stop, I want to control the execution of a DO WHILE loop where a series of actions are performed, including action queries.

Code of the option group:
Code:
Private Sub gStartStop_AfterUpdate()
    If Me.gStartStop = 2 Then 'START button is pressed
        Call XYstat
    Else
        Me.gStartStop = 1 'STOP button is pressed
    End If
End Sub
Partial Code of the XYstat(), the loop:
Code:
Do While Me.valStartDraw > dblStopDraw And [B]Me.gStartStop = 2[/B] '"START"
    Call cmdGetRDraws_Click
    'Show counter
    Me.txtCounter = "CurDraw: " & Me.valStartDraw & vbNewLine & "LoopNo: " & lnCnt
    DoEvents
    Me.cmdGetRDraws.Enabled = False
    
'Create currend bunch of X,Y records
DoCmd.SetWarnings False
    'Empty table
    DoCmd.RunSQL "DELETE * FROM tblRecordsXY"
    'Calculate and append respective records
    DoCmd.OpenQuery "AnalAppendXYrecs", acNormal, acEdit

[B]...etc[/B]
Loop
The problem is that when I click on the STOP button to terminate the loop, I get the error
The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field.
(kindly see the attachment for the full error) and after I press OK the loop continues and finishes normally, doesn't exit.

Anybody with enough experience can tell me what I'm doing wrong?

Thank you!
 

Attachments

  • OptionGroupError.PNG
    OptionGroupError.PNG
    28.7 KB · Views: 150
Have you tried stepping through the code to see if something "unexpected" is happening?

Can you tell us some of the "Why" behind
I want to control the execution of a DO WHILE loop where a series of actions are performed, including action queries.
? (just curious)
 
... nothing unexpected is happening!

I use the START/STOP buttons so that the user, whenever he chooses, can start/stop the filling of records (a series of calculations) .

What I just noticed is that the code works if I use an extra button to change the value of the option group. Of course it might take a while if the loop is performing action queries, but it does it without any errors.. very weird!:confused:

Any thoughts?
 
If you think it might be related to the option group, how about trying 2 buttons Start and Stop.
Should be easy enough to try - although I can't see why a button should be different.

Another option may be to do something on a Timer for XXX units when clicking Start, but that takes away your user can Start/Stop as they wish idea.

Keep us informed of how it 's going. Good luck.
 
If I use a Toggle button to control the Option Group, I get two(2) errors, the one I described above and also: "Error 2110: Microsoft Office Access can't move the focus to the control gStartStop."

Obviously the two errors are related.

However, if I use a use a regular Command button, then it does the job. No errors!

It seems that if I use two Command buttons (Start/Stop), with the extra code involved to enable/disable them accordingly) I would resolve the problem, but then that's like creating my own option button group..! :banghead:

So, the issue remains... why the option group cannot get the focus, whilst the regular command button can get it and pass it to the option group... :rolleyes:

Hope somebody can help out on this...
 
I don't know what is special about the option group.

You can use 1 button, and a boolean to identify state.
( air code not tested)

dim state as boolean
state ="False"

Click event button
make state = not State
if state then caption = "start"
invoke your loop code
else state = "stop"
pause/stop the loop
end if

You're still sort of creating a logical option group, but now it's one regular command button.
 
The special about the option group is the visual effect - pressed/not pressed buttons :)

jdraw, no doubt that your recommendation works, I've tried it already - still one more reason for me to :banghead: why I can get it done with the option group - WHY I get the
Error 2110: Microsoft Office Access can't move the focus to the control gStartStop.
Makes no sense...
 
Here is the code that produces the Error (attached is the mdb copy):
Code:
Option Compare Database
Option Explicit

Dim bnStartStop As Boolean

Private Sub Form_Load()
    bnStartStop = False
    Me.gStartStop = 1 'STOP
End Sub

Private Sub gStartStop_AfterUpdate()
    If Me.gStartStop = 2 Then 'START
        bnStartStop = True
        Call XYZ
    Else
        bnStartStop = False
    End If
End Sub

Sub XYZ()
    Do While bnStartStop = True
        Me.txtDate = Now()
        DoEvents
        Me.gStartStop.SetFocus 'Not really needed...
    Loop

'Ready to re-start
bnStartStop = False
Me.gStartStop = 1
End Sub
If you press START and then STOP of the option group <gStartStop> to break the loop, the error message appears...
So, is it my code or is it an Access peculiar?

I really appreciate anybody's time to resolve it!
 

Attachments

Users who are viewing this thread

Back
Top Bottom