Movian
02-09-2009, 10:03 AM
as you probably guessed from the title this issue is a little complex so i will lay a little background.
I have a main form that has a sub form section. Using buttons on the main form you can change which form is currently being used as the subform. Each subform has a tab control.
so i have a client who INSISTS on being able to look at the same record on two machines.... don't ask i just have to make it work. My solution was to run
DoCmd.RunCommand acCmdRefresh
DoCmd.RunCommand acCmdSaveRecord
for both the subform and the main form (for some reason if i did it just the once it would only save the form that currently had focus) so i ended up producing the following code
If myrs.Fields("AutoSave") = True Then
DoCmd.RunCommand acCmdRefresh
DoCmd.RunCommand acCmdSaveRecord
Me.MedicalID.SetFocus
DoCmd.RunCommand acCmdRefresh
DoCmd.RunCommand acCmdSaveRecord
PreviousControl.SetFocus
End If
Now my issue lies in the issue that if a control on the main form is selected, the focus returns to that control through the previous control function. However if a control on the sub form has the focus the code does not return focus to the selected control but instead keeps focus on the field MedicalID on the main form. This can cause issues as the saving code is on the ontimer event meaning if someone is typing somthing and they get the focus on the medical id they start overiting the medical ID. i have looked through the diffrent options for the screen.previouscontrol etc but i can't even get the form name to manually set the forms("fmMain").controls("fsubmodule").controls(controlname).setfocus value myself as i can only ever return the form name of frmmain or the tab name instead of the subform name....
any help is apriciated.
I have a main form that has a sub form section. Using buttons on the main form you can change which form is currently being used as the subform. Each subform has a tab control.
so i have a client who INSISTS on being able to look at the same record on two machines.... don't ask i just have to make it work. My solution was to run
DoCmd.RunCommand acCmdRefresh
DoCmd.RunCommand acCmdSaveRecord
for both the subform and the main form (for some reason if i did it just the once it would only save the form that currently had focus) so i ended up producing the following code
If myrs.Fields("AutoSave") = True Then
DoCmd.RunCommand acCmdRefresh
DoCmd.RunCommand acCmdSaveRecord
Me.MedicalID.SetFocus
DoCmd.RunCommand acCmdRefresh
DoCmd.RunCommand acCmdSaveRecord
PreviousControl.SetFocus
End If
Now my issue lies in the issue that if a control on the main form is selected, the focus returns to that control through the previous control function. However if a control on the sub form has the focus the code does not return focus to the selected control but instead keeps focus on the field MedicalID on the main form. This can cause issues as the saving code is on the ontimer event meaning if someone is typing somthing and they get the focus on the medical id they start overiting the medical ID. i have looked through the diffrent options for the screen.previouscontrol etc but i can't even get the form name to manually set the forms("fmMain").controls("fsubmodule").controls(controlname).setfocus value myself as i can only ever return the form name of frmmain or the tab name instead of the subform name....
any help is apriciated.