On Click erratic

Pavl

Registered User.
Local time
Today, 03:15
Joined
Jan 17, 2013
Messages
56
Hello.
Beginner using accdb2010 with multiple forms for display only (eventually in runtime with maximum restrictions).
Have FrmSubNav on each main form with command buttons.
These buttons allow selection of another form or closing current form and returning to home form.
(The appropriate button colour and text is changed for each main form to identify its changed properties)

Problem = the OnClick is erratic.
Example for one button on FrmSubNav =

Code:
Private Sub Button08_Click()
If CurrentProject.AllForms("FrmWDYpages").IsLoaded = True Then
    DoCmd.Close acForm, "FrmWDYpages", acSaveNo
    DoCmd.OpenForm "FrmHome", acNormal, "", "", , acFormReadOnly
    Forms.FrmHome.Focus1.SetFocus
Else
    Screen.ActiveForm.Visible = False
    DoCmd.OpenForm "FrmWDYpages", acNormal, "", "", , acFormReadOnly
    Forms.FrmWDYpages.Focus8.SetFocus
End If
There is also a basic error msgbox removed from this example.
When viewing FrmWDYpages the button will close this form and open FrmHome . But if using the same button from a different form it will "hide" the calling form and open FrmWDYpages.
It is the second scenario that sometimes fails.
I get sent to FrmHome instead of the form called by the click.
No error box displayed.
I have been unable to successfully reproduce the failure - it seems to be random.
Speed of mouse click can sometimes prompt the failure (fast).
Success almost always with a second attempt (more deliberate / slow)
Calling form is "hidden" during this failure and FrmHome visible.

Wireless mouse / WinXPpro / <40% RAM usage / dualcore total at between 4% and 15% when clicking between forms.

Should I be using MouseDown/Up ? And if so - how to split code ?
Should the If statement be inverted to IsLoaded False then open with the Else option to do the Close, Open, SetFocus as the second part ?

Thank you.
 
Just to clarify, are you saying that the procedure you have posted is one of several Buttonx_Click procedures in FrmSubNav and that FrmSubNav is a subform on other forms - i.e. FrmWDYpages and FrmHome.
 
Hello CJ_London
Yes that is correct.
8 command buttons including one that is for the FrmHome only so has different code on its own button (Button01)
Other 7 have copies of this code just renamed for the appropriate main forms.
FrmSubNav is a subform on 8 main forms including FrmHome and the example posted. Placed with copy/paste and functions correctly/as expected except for this erratic click behaviour.

Update:
Sometimes the calling form remains open and FrmHome becomes visible (on the "top" tab) when I should be seeing a completely different form.
By closing FrmHome (Qat close) I can click again on the original button and it will work.
Seems to be doing this most of the time now. Daily compact/repair and backups.

Have "inverted" the code to put IsLoaded False and swapped the two sides of Else.
No improvement - same errors.
 
Last edited:
I have a similar methodology but I have the buttons on the main form and open all the other forms in a subform on the main form.

If the subform is called "SForm" then the code behind each button is simply

SForm.SourceObject="Name of form to open"

It means only one 'form' is open at a time but sounds like that is what you are trying to achieve anyway
 
Thank you CJ_London
I am trying to have the user able to move between forms at will and had asked in a previous thread about having all open at once but was advised against that. Was advised to use the Visible property.

Just tried replacing IsLoaded with Visible and just get error.
Am now going to try opening all forms at start instead of just the home form and making all forms Visible = False.
Then make each Visible True/False as needed.

I want each form to retain its status (chosen record in view) when the user moves away to another form and then returns to the first form. And this to be the case for all forms in whichever sequence they are viewed.

There is no user edit or append function - will be a display only runtime DB so it is only the selection of records without any Dirty events (I hope!)

UPDATE
Have loaded all forms and made Visible = False
Changed code to calling form Visible = False and target form Visible = True - then SetFocus to control on target form.

All seems to work as I want. Form record status remains intact when switching between them and the OnClick error seems to have gone.
Will continue to test so this is a provisional "solved" - will update later.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom