Subform Tab Control

andrewbc

New member
Local time
Today, 15:10
Joined
Sep 23, 2009
Messages
3
Hello

I have my main for that has tab control with about seven tabs on it. All but one of these tabs have the enable property set to false. So people can viewclient information. but not change.

Of one of the tabs has another tab control with 3 pages on it. this tab has the enable property set to true but the tabs on the sub form are set to 'enabled = false'. So they cant be changed

At the top of the main form is a command button (edit) that has an on click event procedure and it then changes all of the tab properties to true so information can be changed. even the ones on the sub forms are changed. It also changed the visble property of the edit button so it is hidden and enables a save button to appear.

When staff are finished editing the information they click the save button and if then changes the tabs back to 'enable = false' so that information cant be changed again and also loads another form for users to complete.

This is where my problem comes is. The enable property is changed for the tabs on my main form but on the subform the tabs there dont get changed as it comes up with the following error "Run Time error 2164 You cant disable a control while it has the focus."

I have tried to change the focus to a command button on the main form but i still get this error.

can someone advise what i am missing. I have posted the code i have on save event procedure for you to have a look at. I am an intermediate at VB Code am quick to learn

Thanks in Advance

Andrew C

Private Sub sAVE_Click()
If Me.Dirty Then Me.Dirty = False
If Me.Deceased = True Then
'Client ceased using your services
Me.Active = "No"
Me.DDate.Enabled = False
Me.DDate.Locked = True
Me.Cessation_Reason.Enabled = False
Me.Cessation_Reason.Locked = True
Else
'Client still uses your services
Me.DDate.Enabled = False
Me.Cessation_Reason.Enabled = False
Me.DDate.Locked = False
Me.Cessation_Reason.Locked = False
End If
Me.New_Client.Visible = True
Me.New_Client.SetFocus
Me.General.Enabled = False
Me.Core.Enabled = False
Me.Child246.Form![Page 1].Enabled = False
Me.Child246.Form![Page 2].Enabled = False
Me.Functional.Enabled = False
Me.Living_Arrangements.Enabled = False
Me.Carer.Enabled = False
Me.Child207.Form![Page 1].Enabled = False
Me.Child207.Form![Page 2].Enabled = False
Me.Child207.Form![Page 3].Enabled = False
Me.Psychosocial.Enabled = False
Me.Health_Behaviours.Enabled = False
Me.Label97.Visible = False
Me.Edit.Visible = True
Me.Menu.Visible = True
Me.save.Visible = False
Me.Search.Enabled = True
stDocName = "Updates"
stLinkCriteria = "[Clientsid]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "Client_Active"
Exit_sAVE_Click:
Exit Sub

End Sub
 
- I believe the reason you have a problem is that the code is messy and much too long. It's no wonder you can't figure out what's going on!
- Create one sub-routine that handles your menus and command buttons. One subroutines handles your tab pages. Something. Some scheme that breaks this complicated operation into smaller more manageable chunks.
- I don't recommend hiding control elements like buttons. Disable them if they are not available, but hiding them alters the layout or design of your interface.
- Eliminate duplicate code. If Deceased Then you set DDate.Enabled = False, but in the Else block you also set DDate.Enabled = False. Only do this once.
- Consider this structure...
Code:
If A = True then
  B = False
Else
  B = True
End If
This is expressed much more succinctly by
Code:
B = Not A
I expect you can use this reasoning to further simplify your code.
Cheers,
 

Users who are viewing this thread

Back
Top Bottom