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

Don't save complete record -

Status
Not open for further replies.

buckeye77

Technical User
Jul 21, 2008
29
US
How do I tell a form that if field [txtfirstname] is not complete, then don't save that record on exit or closing of the form?
Perferably a pop up box (yes / no) notifing the user the record would display.
Yes = exit and not save record
No = cancel the exit and go to the field txtfirstname

I think this would help stop all the empty records I am seeing.
 
Perhaps this FAQ may help:

However, I think I would be inclined to set AllowAdditions to False and to create an AddRecord button and form. The form would be unbound and would only ask for certain minimum information, perhaps only the name. If the data validated, the record could be added, the main form requeried and the user could be taken to the new record. If the data did not validate, the user could correct the data or cancel the addition.
 
I have never been to good at the "public" items. Below is something that I have been playing with that may be a start... any suggestions?
__________________________________________
Private Sub Command14_Click()
If Me.txtFirstName = Null Then
Select Case MsgBox("record incomplete need information - cancel record?", vbYesNo, "Incomplete Record")
Case vbYes
DoCmd.CancelEvent
DoCmd.Close
Case vbNo
Me.txtFirstName.SetFocus
Else
DoCmd.Close
End If
End Select
End Sub
____________________________________________
The issue I have right now is that the errr shows "Else" without "If" but don't I have the "if"?
 
You may get away with undo. Try it and see.

Code:
Private Sub Command14_Click()
'Name this command button to something sensible
'you will thank yourself later.

If Trim(Me.txtFirstName & "") = "" Then
'Because it could be a space filled string

   'Note: Always indent your code
   'No need for select, there are only two choices.
   If MsgBox("record incomplete need information - cancel record?", _
        vbYesNo, "Incomplete Record")=vbYes Then

      'Access saves by default, so undo
      Me.Undo
      'Best to specify
      DoCmd.Close acForm, Me.Name
   Else
      Me.txtFirstName.SetFocus
   End If
Else
   'What ever you want to do if txtFirstName is complete
   'You may not wish to do anything
End If
End Sub
 
You have "End Select" in the wrong place and nothing = NULL ... not even NULL. You need to use the IsNull function.
Code:
Private Sub Command14_Click()
    If IsNull(Me.txtFirstName) Then
        Select Case MsgBox("record incomplete need information - cancel record?", _
                           vbQuestion + vbYesNo, _
                           "Incomplete Record")
            Case vbYes
                DoCmd.CancelEvent
                DoCmd.Close
            Case vbNo
                Me.txtFirstName.SetFocus
        End Select
    Else
        DoCmd.Close
    End If
End Sub
[
 
Thank you all! The "undo" takes care of the problem. When I corrected my original formula with Golom's help, I found that it was not "undoing". However, with the "undo", no records are being saved.

Thanks again to all for the help! I have been away from access for a long time and it is like learning everything all over.
 
IsNull(Me.txtFirstName) will only account for Null names. If a user idly enters a space, it will be accepted as a name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top