Results 1 to 3 of 3
  1. #1
    darekg11 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2012
    Posts
    7

    Code to check if field is empty


    Code:
    Private Sub Anuluj_Click()
    Dim final As String
    Dim data As String
    If Nz(id_dostawcy, "") & "" <> "" Then
    DoCmd.Close
    DoCmd.OpenForm "Dostawcy_główny"
    Else
    DoCmd.SetWarnings False
    MsgBox ("CHECK")
    data = id_dostawcy.Value
    DoCmd.Close
    final = "DELETE * FROM Dostawcy WHERE id_dostawcy = " & data & ";"
    DoCmd.RunSQL final
    DoCmd.OpenForm "Dostawcy_główny"
    DoCmd.SetWarnings True
    End If
    End Sub
    id_dostwacy is field which hold unique ID of record and is aumatically entered by acNewRec now I have Cancel button on form and when I press it without enterin fields on form like name, second name etc it was crashing due to NULL value in id_dostawcy so I made this code but it never go to else code even if dostwacy_id is filled.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why would id_dostawcy be null? If your procedure automatically creates this value when going to new record how can the control be null? If id_dostawcy is an autonumber type field, just going to new record does not actually create a record. Should be able to simply quit the form unless something else is happening. Do you have other fields/controls set with DefaultValue? If data is entered into any field, this will initiate a record. Need to Undo before trying to close form if you want to cancel. Delete won't work because the record is not yet committed to table, there is no record to delete.

    Want to provide db for analysis? Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    darekg11 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2012
    Posts
    7
    Hey man, thanks for Your answer but I have already solved it. I was so stupid to put "if" code in place of "else" code and "else" code to "if" code. Now when I changed it, it works without a problem but still thank You.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-23-2012, 10:13 PM
  2. code to delete rows based of empty cells
    By jcbrackett in forum Programming
    Replies: 3
    Last Post: 03-05-2012, 02:27 PM
  3. check empty table
    By ramdandi in forum Queries
    Replies: 1
    Last Post: 12-20-2011, 04:31 PM
  4. Check if fields are empty
    By Doggfather22 in forum Forms
    Replies: 3
    Last Post: 12-02-2010, 11:03 AM
  5. empty field
    By amber mara in forum Access
    Replies: 2
    Last Post: 05-05-2010, 01:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums