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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check form is complete before saving 2

Status
Not open for further replies.

frantik

Technical User
Nov 9, 2002
93
GB
Hi

I have a form containing a subform. There are certain fields I want to check are completed before the record is saved. If they are not complete the user is taken back to that field.

I have used the following code behind the save and Exit Button:


If IsNull(Me!Combo116) Then
MsgBox "Please enter a valid Project Number"
Me.Combo116.SetFocus
Else

If IsNull(Me!Cb_Cat) Then
MsgBox "Please enter a valid Category"
Me.Cb_Cat.SetFocus

Else

If IsNull(Me!Combo23) Then
MsgBox "Please enter a valid Location"
Me.Combo23.SetFocus

Else
If IsNull(Forms!Fm_Risk_ass.Fm_Chosen.Form!Combo11) Then
MsgBox "Please Ensure you have Selected the Chosen Option "
Me!Fm_suboptions.SetFocus

Else

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close

End If
End If
End If
End If

It works for the first two cases - but not the last two - although it has worked for all options in the past - it seems to have stopped working and I don;t know why - can anyone help please?.

 
What is it intended to do? What does it do?

It might be an issue of a form control returning zls ("") in stead of Null, and testing with:

[tt]if trim$(me!txtControl.value & "") = "" then
' contains nothing
end if[/tt]

But what you most likely are up against, is that the the only event where you can reliably test/validate a record prior to saving, is the before update event of the form. So I'd suggest placing the validating code there, issuing a

[tt]cancel = true[/tt]

if the validation fails. Also try the above test in stead of IsNull, in case the controls may return zls.

Roy-Vidar
 
How are ya frantik . . . . .

Try this:
Code:
[blue]   If Trim(Me!Combo116 & "") = "" Then
      MsgBox "Please enter a valid Project Number"
      Me.Combo116.SetFocus
   ElseIf Trim(Me!Cb_Cat & "") = "" Then
      MsgBox "Please enter a valid Category"
      Me.Cb_Cat.SetFocus
   ElseIf Trim(Me!Combo23 & "") = "" Then
      MsgBox "Please enter a valid Location"
      Me.Combo23.SetFocus
   ElseIf Trim(Forms!Fm_Risk_ass.Fm_Chosen.Form!Combo11 & "") = "" Then
      MsgBox "Please Ensure you have Selected the Chosen Option "
      Me!Fm_suboptions.SetFocus
   Else
      DoCmd.RunCommand acCmdSaveRecord
      DoCmd.Close
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks Guys

Its working perfectly now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top