Can't set focus error or OpenForm action canceled error (1 Viewer)

Thicko

Registered User.
Local time
Today, 07:17
Joined
Oct 21, 2011
Messages
61
Hi All,

Apologies for the bad explanation.

I have a some code used to test frmChemoRecord, it loops through various scenarios completing the form with a range of different values to test the output.

The problem comes when it gets to the
Code:
DoCmd.OpenForm "frmDateSelect", acNormal, , , , acWindowNormal
it throws up a OpenForm action cancelled error.

I press Debug then click Continue and it runs fine.

I've tried various things one of which is to use the button on frmChemoRecord that opens the frmDateSelect (to output the results), if I do that I get a Can't setfocus error on
Code:
[Forms]![frmChemoRecord].[RuReportButton].SetFocus
. Again press Debug then click Continue and it runs fine and this time there's no error thrown up in OpenForm code. This happens during each test loop.

I can't explain why something is causing an error at this particular point in the code. Is it possible that the code running on frmChemoRecord is not completing before the testing loop is moving onto trying to output the results report. If so is there a solution?

All ideas welcome
Many Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:17
Joined
Oct 29, 2018
Messages
21,358
Hi. Perhaps the best way to help you troubleshoot this is if you could post a sample copy of the db showing the error.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:17
Joined
Feb 28, 2001
Messages
27,001
Generally, native Access is single-threaded for a given user. However, if you are using something like an active SQL-based server as your back-end, you could have timing issues because there, two CPUs are involved.
 

Thicko

Registered User.
Local time
Today, 07:17
Joined
Oct 21, 2011
Messages
61
Thanks all, I will do a bit of deconstruction to post a bit of the database with the issue, might even come clearer by doing it.
 

Micron

AWF VIP
Local time
Today, 03:17
Joined
Oct 20, 2018
Messages
3,476
One thing that can raise the first issue you mentioned is where FormA code branches off and opens FormB but code in B cancels the opening. When code execution resumes in A, the cancelled opening of B is reported in the message you describe. If you cannot avoid the situation, the fix would be to trap the error in code in FormA.
 

Thicko

Registered User.
Local time
Today, 07:17
Joined
Oct 21, 2011
Messages
61
All sorted, thanks for the insight.

Micron was on the right track. The frmValidation code was trying to open frmDateSelect, that caused frmChemoRecord to run the AfterInsert code, part of which included the code to open frmDateSelect and later close it which was causing the problem when frmValidation tried to open frmDateSelect.

A simple
Code:
If ValidationMode = False Then DoCmd.Close acForm, "frmDateSelect"
prevented frmChemoRecord from closing frmDateSelect and then on frmValidation a
Code:
If CurrentProject.AllForms("frmDateSelect").IsLoaded = False Then DoCmd.OpenForm "frmDateSelect", acNormal
prevented the conflict.

Relieved.

Many Thanks
 

Micron

AWF VIP
Local time
Today, 03:17
Joined
Oct 20, 2018
Messages
3,476
Glad to hear you solved it. If only 2 forms are involved (in this case, it seems not) my typical approach would be to trap the error in formA (I think the number is 2501) assuming the situation can't be avoided entirely. It's advisable to have error handlers in most procedures so my viewpoint is why not just take advantage of them when you can?
 

Users who are viewing this thread

Top Bottom