Results 1 to 3 of 3
  1. #1
    Randy is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    Jun 2010
    Posts
    48

    SQL Insert Into Fails

    The following SQL event will not update the CustomerData table if the FrmContact field on the form is left blank. I have this code in the OnLostFocus Event. Is it possible to have this command update the fields that do have data entered in them even though the FrmContact field is blank?



    DoCmd.RunSQL "INSERT INTO CustomerData (CustomerName, CustomerAddress, CustomerCityStateZip, CustomerPhone, CustomerContact, LockRecs) " & " VALUES (""" & Forms!frmflcdeliver.Controls!FrmCompany & """ , """ & Forms!frmflcdeliver.Controls!FrmAddress & """, """ & Forms!frmflcdeliver.Controls!FrmCityStateZip & """, """ & Forms!frmflcdeliver.Controls!FrmPhone & """, """ & Forms!frmflcdeliver.Controls!FrmContact & """, """ & Forms!frmflcdeliver.Controls!FrmLocked & """)"

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Don't need the .Controls qualifier, although probably not an issue.

    I think problem is the value is delimited as text so Null causes error. Use IIf to handle possible Null.

    Is this code behind frmflcdeliver? If so, can use Me alias. I prefer apostrophe instead of two quote marks for text delimiter.

    & IIf(IsNull(Me.FrmContact), Null, "'" & Me.FrmContact & "'") &
    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
    Randy is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    Jun 2010
    Posts
    48
    Thank you Jun7: I haven't tried it yet but I will reply back with the outcome.

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Return Row Identity after Insert Fails
    By rukie in forum Programming
    Replies: 1
    Last Post: 12-03-2012, 08:59 PM
  3. If insert query fails, then
    By redbull in forum Queries
    Replies: 3
    Last Post: 07-23-2012, 10:08 AM
  4. query fails
    By rjjhome in forum Queries
    Replies: 4
    Last Post: 03-15-2012, 05:19 PM
  5. Requery fails
    By Dega in forum Forms
    Replies: 3
    Last Post: 09-28-2010, 08:35 AM

Tags for this Thread

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