Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent user going to next rcd until date entered.

Status
Not open for further replies.

andagain

Technical User
May 28, 2004
25
GB
HI,

If I want to prevent my user from navigating (using the default buttons) to the next record until they have entered a date into the field 'Registrationdate', what do I need to do other than using the code below, which is fine for an initial prompt, but obviosly won't stop them going to the next record'

Code:
Private Sub Registrationdate_LostFocus()
If IsNull(Me.Registrationdate) Then
MsgBox "Please enter a Registration Date for this client"
End If
End Sub

Thanks,

Andrew.
 
Take a look at the BeforeInsert and BeforeUpdate event procedures of the form.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
After the MsgBox type;

Cancel = True

I haven't failed, I have just found 10,000 ways that it won't work!
 
Thanks people.

txaccess's method works, except that when the user navigates to another record, but when the msgbox displays clicking "OK" clears the data already filled in the form.

How do I stop it doing this?

Playing with beforeinsert & beforeupdates PHV...ta..

Andrew.
 
Put the code in the BeforeUpdate event of the field and this should solve the problem.

I haven't failed, I have just found 10,000 ways that it won't work!
 
Thanks a lot.

Does what I want, Nice one.

Andrew.
 
Hi there guys....I hope you might still pick this thread up.

Just realised that this method to stop the user leaving the field empty only seems to work if the date is entered and then deleted; only then will the message box appear if the field is then left blank, and then the user is prevented from doing anything else until they enter the date. If the user just starts a new record, they can leave the Registration date empty and fill in the rest of the fields and they are able to go to another record or tab.

I have this code on my text box:

Private Sub Registrationdate_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Registrationdate) Then
MsgBox "Please enter a Registration Date for this client. Thank you."
Cancel = True
End If
End Sub

I also have:

Private Sub Form_AfterUpdate()
Me.Registrationdate.SetFocus
End Sub

Any ideas what I've got wrong????

Thanks, Andrew.
 
Replace this:
If IsNull(Me.Registrationdate) Then
By this:
If Trim(Me.Registrationdate & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Cheers PHV, but this seems to just do the same thing, ie. it only works when you enter then delete a date, and then try to move on. On a new record it will let you initially leave the date blank without the message box displaying....

?
 
I would take another look at PHV's initial suggestion, using the before update event of the form. It is probably the only reliable way of preventing a save with uncomplete record (it won't prevent the user from jumping from control to control, but it will prevent save/moving to next record...)

Roy-Vidar
 
Hey, thanks.
Realised I was concentrating on putting the code in BeforeUpdate of the field textbox rather than of the form (as you first suggested PHV, but which I misread) Doing this gives me the result I want.

Thanks again

Andrew.
 
Hi there people - hoping you'll still pick up this thread - I have related problem that I am stumbling on......

How do I apply the same method to make sure my user fills in a particular control (duration) on a continous record subform (interactionssubform) within my form. The subform is on another page if that has any implications....

I just want to stop them going to a new or another record until they have entered some data into duration on the subform....Can I just put some more similar code (to what I did in the above example) in the beforeupdate event of my main form? How do I do that...like this?

Private Sub Registrationdate_BeforeUpdate(Cancel As Integer)

If Trim(Me.Registrationdate & "") = "" Then
MsgBox "Please enter a Registration Date for this client. Thank you."
Cancel = True
End If

If Trim(Forms!Interactionssubform!Me.Duration & "") = "" Then
MsgBox "Please enter a duration for this client. Thank you."
Cancel = True
End If

End Sub

Can you do that...have two If Then thingys in one event of a form?

Am I on the right track or completely off the ball? ? ? ?

Sorry, I still haven't had any time to learn this stuff...just getting by....

Thanks for any help.

Andrew.
 
Replace this:
If Trim(Forms!Interactionssubform!Me.Duration & "") = "" Then
By this:
If Trim(Me!Interactionssubform.Form!Duration & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Couldn't you just set the "Required" value in the table design to "Yes".

Or won't that work for some reason?
 
Cheers PHV, but I have run into trouble.....

I have this in the BeforeUpdate of my main Form:

If Trim(Me!Interactionssubform.Form!Duration & "") = "" Then
MsgBox "Please enter a duration for this client. Thank you."
Cancel = True
End If

But I get the error: Cannot find the field 'Duration'.

Duration is the name of the field and control I want the user to fill. It is in a Subform called Interactionssubform (bound to table Interactions).

(I want to do it in the BeforeUpdate of my main form because my user may be tempted to not bother navigating to the page/tab that contains Interactionssubform).

Any ideas what I am doing wrong? I tried the slightly method you gave in your reply to my new thread post of the same question but that doesn't work either.

Am I not telling access where to look for the field Duration correctly?

Thanks for your help again.

Andrew.
 
where to look for the field Duration correctly
To find the syntax for addressing the Duration control, try the Expression builder playing with loaded forms.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top