2 minutes of your time please

rnickels

Registered User.
Local time
Today, 01:48
Joined
Dec 8, 2006
Messages
48
Hello all,

This forum has been a lifesaver in the past and I hope someone can help me now.

I have a Contacts form that is used to input all the client's information. (name, date of birth, address etc).

I want to be able to force the person entering the data to not be allowed to tab to the 2nd text box (or any other text box on the page) unless in the first text box data has been entered (the first text box is client name)

However, I also need to be able to overide this if the person entering the data clicks on a "Cancel" button (another button on the page which closes the form).

Is this possible and if it is any help would be greatly appreciated!

Thank you in advance,

Rob
 
Try putting some code in the Exit event of the control. You can hold the focus in the control with Cancel = True in that event.
 
Create a new button, and in it disable all the controls except the one you require entry for. Then create a save button, where you test if data has been entered if so save and enable rest of form.

Hint
use a procedure to enable/disable controls like this

sub DisableEnable(bFlag as boolean)
me!mycontrol.enables=bflag
end sub

to disable controls
disableEnable false

to enable controls
disableEnable true
 
Thank you Rural Guy

All I needed was 3 words of code!!!!
People like you make building databases look so easy!

Thanks so much
 
It Nearly works

I used your cancel=true in the on exit property of the text box.
It does disable the user from tabbing to another text box but I have a question.
I entered the data into the first text box but after doing so it still prevents me from tabbing to the next text box on my form.
Can you help?

Rob
 
use the below

if isnull(me.[ControlName])=true then
cancel=true
end if
 
Hi Rob,
You will need to do a couple on things more. Your code in the Exit event should be checking two things. 1) should we bypass the test flag from your other control and 2) is this control properly completed. Your Exit event will look something like:
Code:
Private Sub txtClientName_Exit(Cancel As Integer)

If Not Bypassing Then
   If Len(Me.txtClientName & "") = 0 then
      MsgBox "Please enter a Client Name!"
      Cancel = True
   End If
End If

End Sub
...using your control and variable names of course.
 
Nearly but not quite working

Both Keith G and Rural Guy.....both you ways worked but there is one more thing.

Let's suppose I enter a name in the client name field and then tab to another field...so far so good......but then if Igo back into the first text box (client name) and delete the name Ihad just entered and tab out again (yes,i know i am assuming that the user is not the smartest tol in the shed) i get an annoying error message:

The field playername cannot contain a null value because the required property for this field is set on true. Please enter a value in this field.

Can I a) create my own error message or b) prevent this error message from appearing?

Thanks for your help

Rob
 
use this



if isnull(me.[ControlName])=true or Len(Me.[ControlName])<1 then
cancel=true
end if
 
Put code in the BeforeUpdate event of the control to catch the user clearing the field. You can do almost *any* sort of validity checking in that event and use Cancel = True to hold the user in the control.
 
Thanks Keith but it still gives me the error message

I tried but it still gives the error message.
Any other suggestions?
Thanks so much for helping me.

Rob
 
Please post the code you put in the BeforeUpdate event of the control.
 
It's sort of working!

I have figured out how to make sure that if no name is entered in the playername text box then the user cannot tab into the next box....
Now for the next issue...
I have a button on the form with the following on click code:

Private Sub OLEUnbound199_Click()
If IsNull(Me.PlayerName) = True 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

My problem is this and I hope it's an easy solution for your sake as you've already helped me out a great deal...
If a name has been entered into the playername text box and then deleted by the user......by theory if i then click the button (wihich has the on click code above) it should see the playername text box as null and pop up my error message......but it doesn't. I assume that as there has been data entered into the playername (even though it was then deleted) it doesn't read it as a null.
Thanks for any future help and for all previous help.
Rob
 
You should go to Access Help and key in EVENTS. There is a good description of the sequence of events for almost everything. When you click the button you are describing, there are a bunch of events in the TextBox that take place BEFORE the focus can be moved to the button. If you coded the events properly then the system will *not* allow the focus to shift to the button if the TextBox is empty! Please post the BeforeUpdate event code you have in the PlayerName control. I just tested the idea and it works as expected.
 
Thanks Rural Guy

Here is my code on the beforeupdate for the playername control:

Private Sub playername_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[PlayerName]) = True Or Len(Me.[PlayerName]) < 1 Then
Cancel = True
End If
End Sub

I also have this code on the on exit property as the above code did not work correctly on its own:

Private Sub playername_Exit(Cancel As Integer)
If IsNull(Me.[PlayerName]) = True Or Len(Me.[PlayerName]) < 1 Then
Cancel = True
End If
End Sub
 
Try changing your BeforeUpdate event to:
Code:
Private Sub playername_BeforeUpdate(Cancel As Integer)

If Len(Me.playername & "") = 0 Then
   MsgBox "Entry Required", vbCritical + vbOKOnly
   Cancel = True
End If

End Sub
...so we can be sure of what is executing. My field is Required and I do not get an error other than my MsgBox. What version of Access are you using?
 
Me again

I am using Access 2002.

The code you just sent me does not work on its own. I also have to use the code in the on exit property.
 
Agreed but you should not be getting any errors other that the MsgBox.
 
try this

is it relavent that the command button on the form is actually an image?
 
I don't believe it should make any difference. What error are you getting again?
 

Users who are viewing this thread

Back
Top Bottom