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

Procedure for closing form containing blank/null required fields

Status
Not open for further replies.

bikerted

Technical User
Nov 7, 2003
221
0
0
GB
I'm unsure if I sent this already but my thread history tells me I failed to send. However, could someone assist with an effective way of doing the above. I have looked through FAQ's, searched through this site and looked on Microsoft's help site, but stil I'm confused. The following procedure, which I know is not right, does not seem to fit the bill:
Code:
Private Sub Label26_Click()
On Error GoTo Err_CloseForm_Click
If IsNull(Me!DeptPrefixcbo1) And IsNull(Me!ProductIDcbo) And IsNull(Me!aRIDcbo) Then
   
  MsgBox "All fields on this form are required"
   
   Exit Sub
ElseIf IsNull(Me!DeptPrefixcbo1) Then
   MsgBox "Dept Prefix must be added", vbExclamation
   Me!DeptPrefixcbo1.SetFocus
ElseIf IsNull(Me!ProductIDcbo) Then
   MsgBox "Product must be added", vbExclamation
   Me!ProductIDcbo.SetFocus
ElseIf IsNull(Me!aRIDcbo) Then
   MsgBox "Area Responsibility must be added", vbExclamation
   Me!aRIDcbo.SetFocus
Else
DoCmd.Close
End If
Exit_CloseForm_Click:
Exit Sub
Err_CloseForm_Click:
   MsgBox Err.Description
   Resume Exit_CloseForm_Click
End Sub

The upshot is: 1. The three required fields on this form should be tested for " " (I assume rather than null). 2. If not " " the form can be closed and the new record saved. 3. If any are " " then focus on each to give the option to input data and then close. I realise this code is only if best part way there but can someone nudge me in the right direction.

I should be most grateful.

Ted.
 
What about this ?
Code:
Private Sub Label26_Click()
If Trim(Me!DeptPrefixcbo1 & "") = "" Then
   MsgBox "Dept Prefix must be added", vbExclamation
   Me!DeptPrefixcbo1.SetFocus
   Exit Sub
End If
If Trim(Me!ProductIDcbo & "") = "" Then
   MsgBox "Product must be added", vbExclamation
   Me!ProductIDcbo.SetFocus
   Exit Sub
End If
If Trim(Me!aRIDcbo & "") = "" Then
   MsgBox "Area Responsibility must be added", vbExclamation
   Me!aRIDcbo.SetFocus
   Exit Sub
End If
DoCmd.Close
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks for your reply. That procedure worked fine for the first field and then only once (I was able to close the form on the second click of the close button), and not at all on the remaining fields. I tinkered a little by substituting ElseIf, with the same result.

Any ideas?

Ted.
 
Sorry to labour this one, but if anyone has an idea how to crack the above I should be most grateful. The procedure (with my untrained eye) looks perfectly adequate - especially coming from a top tipster, but will not prevent form closure with blank fields for all but the first control in the procedure (DeptPrefixcbo1) - and this only once. Any suggestions?

Thank you,

Ted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top