Results 1 to 2 of 2
  1. #1
    Tyork is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    35

    SQL Update with blanks

    I have an update statement that updates a table based on form entries. The entries are a combination of text values and dates - 11 in total. The form is unbound. The statement executes properly when all form fields are filled in. If an entry is left blank I'm thrown a syntax error:



    Run-time error '3075'
    Syntax error in date in query expression '#'.

    The code is as follows:

    Code:
     
    SQLUpdate = "UPDATE EMS_Main SET DSP3Date = #" & Me!DSP3Date & "#, DSP3Result = '" & Me!DSP3Result & "', DSP5Date = #" & Me!DSP5Date & "#, DSP5Result = '" & Me!DSP5Result & "', BCDate = #" & Me!BCDate & "#, BCResult = '" & Me!BCResult & "', BackgroundNumber = '" & BackgroundNumber & "', OFACDate = #" & Me!OFACDate & "#, OFACResult = '" & Me!OFACResult & "', FDate = #" & Me!FDate & "#, FResult = '" & Me!FResult & "' WHERE EmployeeName = '" & Employee & "'"
    I'm not sure how to code for blank entries. My only thought is that I can write something to dynamically build the sql statement based upon what entries are made. I'd rather not do that though.

    Any help would be appreciated.

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you need to check nulls one by one ( you may not need to check nulls for text fields if you want update them to "" if nothing is in the textbox control.):
    SQLUpdate = "UPDATE EMS_Main SET DSP3Result = '" & Me!DSP3Result & "', DSP5Result = '" & Me!DSP5Result & "', BCResult = '" & Me!BCResult & "', BackgroundNumber = '" & BackgroundNumber & "', OFACResult = '" & Me!OFACResult & "', FResult = '" & Me!FResult & "' "
    if not isnull(Me!DSP3Date) then SQLUpdate= SQLUpdate & ", DSP3Date = #" & Me!DSP3Date & "# "
    if not isnull(Me!DSP5Date) then SQLUpdate= SQLUpdate & ", DSP5Date = #" & Me!DSP5Date & "# "
    if not isnull(Me!BCDate) then SQLUpdate= SQLUpdate & ", BCDate = #" & Me!BCDate & "# "
    if not isnull(Me!OFACDate) then SQLUpdate= SQLUpdate & ", OFACDate = #" & Me!OFACDate & "# "
    if not isnull(Me!FDate) then SQLUpdate= SQLUpdate & ", FDate = #" & Me!FDate & "# "
    SQLUpdate= SQLUpdate & " WHERE EmployeeName = '" & Employee & "'"

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

Similar Threads

  1. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 PM
  2. Access filter does not show blanks
    By Jaricketts in forum Access
    Replies: 1
    Last Post: 03-26-2010, 05:38 PM
  3. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 AM
  4. Adding columns that contain blanks.
    By Tony McGuire in forum Access
    Replies: 11
    Last Post: 05-31-2009, 12:58 PM

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