PDA

View Full Version : tab control, sub form acCmdSaveRecord prvious control problem



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.

OBP
02-10-2009, 06:05 AM
Have you tried using the me.Parent.Subform.control syntax?
I am not sure that I understand why you are doing this though, what is the problem of displaying the same record on 2 different machines. You can set the Table's Record Locking properties to allow more than 1 person to view the data, but only 1 to actually Edit it. The second "Viewer" is notified when the Record is free to edit on their Computer.

Movian
02-10-2009, 08:13 AM
The problem is that they have two machines, one is a tablet and another is a desktop. They Create a NEW record on the tablet and enter data. Then without moving or logging of they move to the desktop, but when they search for the patient record it claims it is not there. Also could you point me in the direction of those record locking options? i would like to look over them and see if i can use them in the system.

OBP
02-10-2009, 08:30 AM
Have you forced a Record Save on the tablet machine. Quite often the record is written to the table but not "displayed"/"released", sometimes not until the form is closed or you move to a new record.
See the Main Menu>Tools>Options>Advanced for Record locking.

Movian
02-10-2009, 08:55 AM
That was essnetially what i was trying to do. So that the information would be displayed on the second machine. However The record locking will not work in this case because they leave the tablet on the patients record then want to edit the same record on the other machine. So the code i have is trying to force the save and refresh so any new records are shown. My other clients should be happy with the record locking. But i still need to find out how to force the save on both the main form and the sub form and keep focus on the current control...

OBP
02-10-2009, 09:16 AM
You could store the Record (s)in a Public/Global Variable, close the form and then re-open it and move to that record.
Or better still update the Table with a VBA Recordset, that is probaly not controlled by Record locking.

CreganTur
02-10-2009, 09:32 AM
When you work with DAO recordsets, one of the parameters you can specify the type of recordset to open. The dbOpenTable type is basically a mirror of your table, and it will reflect any changes recently made to your table. If that doesn't meet your needs, then look into dbOpenDynamic.

HTH:thumb