Hi,
I have a form, with a sub form on it, and the sub form has two subforms of its own. I want the main form to only display one of the sub sub forms depending on a field on the main form. The code I'm using is below. The problem I'm having is that when I change records or load the form it says I can't hide a form that has the focus. I've searched other posts to find a solution but none of them work! I've tried setting the focus to a field on the parent form (me.notes.setfocus) and I've tried setting the focus to one of the fields on the sub sub form that I'm not trying to hide but I still get the error message.
Also now that I think about it, there is another problem with this code. The first isnull if statement always never returns true. I'm giving it the result of a query that either returns nothing or only one record. How do I make a msgbox pop up if nothing is returned?
Many many thanks and sorry for the long post.
Tom
I have a form, with a sub form on it, and the sub form has two subforms of its own. I want the main form to only display one of the sub sub forms depending on a field on the main form. The code I'm using is below. The problem I'm having is that when I change records or load the form it says I can't hide a form that has the focus. I've searched other posts to find a solution but none of them work! I've tried setting the focus to a field on the parent form (me.notes.setfocus) and I've tried setting the focus to one of the fields on the sub sub form that I'm not trying to hide but I still get the error message.
Code:
Private Sub Form_Current()
If IsNull(Me.Restricted_membership_purchases_subform.Form![membership type purchased]) Then
MsgBox ("THIS PERSON IS NOT A MEMBER")
Else
If Me.Restricted_membership_purchases_subform.Form![membership type purchased].Value = "normal" Then
[Customer Spectation Hour Purchases].Visible = True
[Customer Unlimited time purchased].Visible = False
[Spectate Balance Sub].Visible = True 'spectation text box
[Label108].Visible = True 'spectation label
[Label84].Visible = True 'spectation label
Me.Notes.SetFocus
Me.[purchase activity hours].Form![Activity Hours Prices - Normal subform].Form.Visible = True
Me.[purchase activity hours].Form![Activity Hours Prices - premium subform].Form.Visible = False
Else
If Me.Restricted_membership_purchases_subform.Form![membership type purchased].Value = "premium" Then
[Customer Spectation Hour Purchases].Visible = False
[Customer Unlimited time purchased].Visible = True
[Spectate Balance Sub].Visible = False 'spectation text box
[Label108].Visible = False 'spectation label
[Label84].Visible = False 'spectation label
Me.[purchase activity hours].Form![Activity Hours Prices - premium subform].Form.Combo4.SetFocus
Me.[purchase activity hours].Form![Activity Hours Prices - Normal subform].Form.Visible = False
Me.[purchase activity hours].Form![Activity Hours Prices - premium subform].Form.Visible = True
Else
MsgBox ("This person seems to have an undefined member type")
End If
End If
End If
If [Banned] Then
MsgBox ("Warning: This User is banned")
End If
End Sub
Also now that I think about it, there is another problem with this code. The first isnull if statement always never returns true. I'm giving it the result of a query that either returns nothing or only one record. How do I make a msgbox pop up if nothing is returned?
Many many thanks and sorry for the long post.
Tom