2 minutes of your time please

hey

not getting an error message..it's just that when i click on the button (image) it should pop up a message saying the playername box is empty(isnull). if there is a playername entered then the form should close as normal.

this is the on click code i am using:

Private Sub OLEUnbound199_Click()
If IsNull(Me.PlayerName) = True Or Len(Me.[PlayerName]) < 1 Then
MsgBox "You must enter the Player's name!", vbOK, "Tennis Center Business Manager 2007"
Exit Sub
End If
DoCmd.OpenForm "Switchboard", acNormal
DoCmd.Close acForm, "Client Information", acSaveYes

End Sub
 
Are you getting *any* action when you click on your image?
 
answer

Yes the form is closing and the switchboard is opening as it should do (but only if the playername is not empty).

If the playername is empty it should not close.
 
So it is closing *everytime* regardless of the condition of the PlayerName control?
 
In my testbed, the BeforeUpdate event catches the empty control *every* time I try and move the focus. I even put an Unbound OLE control on there to see if the results were different. They were NOT!
 
I'm convinced there is something *else* going on. Any chance you can post your db with any sensitive data removed? Compact and Repair before you zip it up and it would need to be < 394KB to post.
 
Hey, Rural Guy

I cracked it! Now the unbound image that closes the form, only closes if there is a value in the playername text box, regardless of whether I had entered a name and then deleted it. I think the nz(Me.playername) covered all bases.

I added this to the VB code (the red part)

Private Sub OLEUnbound199_Click()
If Len(Me.[PlayerName]) < 1 Or IsNull(Me.PlayerName) = True Or (Me.PlayerName) = Nz(Me.PlayerName) Then
MsgBox "You must enter the Player's name!", vbOK, "Tennis Center Business Manager 2007"
Cancel = True
Exit Sub
End If
DoCmd.OpenForm "Switchboard", acNormal
DoCmd.Close acForm, "Client Information", acSaveYes
End Sub
 
Phew 1 more question

I also have a cancel button on the form which I want to use if i do not wish do add a new playername (and contact information). Basically this is a button which a user would press if they had accidently opened up this page and want to return to the switchboard.

Is there a way to overide the need to enter a playername so that i can just close the form and open the switchbard as needed.
Here is my on click code currently:

Private Sub OLEUnbound57_Click()
DoCmd.OpenForm "Switchboard", acNormal
DoCmd.Close acForm, "Client Information", acSaveNo

End Sub

This closes the form as needed BUT also a msgbox appears (actually it appears twice )becasue of the before update and onexit VBA i entered for the playername text box demanding a playername.

Surely there's a way. Can you help
 
Didn't I suggest you put a Public Boolean variable named Bypassing that you test for and set it true in your close button?
 
Sorry, I don't know what you mean by a boolean!

Hi,
I am sorry but I am not aware of what you are referring to.
Would this bypass the onexit and beforeupdate vb code from my text box?
 
You could keep track of how many times the user tried to escape and ask the user if they need to bypass this test after a certain number of tries.
 

Users who are viewing this thread

Back
Top Bottom