Focus woes

tomdee

Registered User.
Local time
Yesterday, 23:08
Joined
Jul 27, 2004
Messages
16
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.
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
 
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?

Using the debugger, single-step through this code by setting a breakpoint on the first IF statement. There is a debugging option that causes Access to automatically evaluate anything you put your cursor on. So put your cursor on the argument of the IF and see what its value is - if any.

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.

Set focus BEFORE changing the visibility of anything.
 
Thanks for your help regarding this, however I'm still unable to resolve either of the two issues.
The line:

Code:
If IsNull(Me.Restricted_membership_purchases_subform.Form![membership type purchased]) Then

is evaluating to false whether [membership type purchased] is null or not.


And I have been setting the focus before trying to make things visible or not. The lines that are cuasing the problem are:

Code:
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

and the corresponding ones in the else part. As you can see I've done:
Code:
Me.Notes.SetFocus
before trying to change visibility but it's still giving me the error on those lines.
 

Users who are viewing this thread

Back
Top Bottom