Results 1 to 9 of 9
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Any way to clear field data when using unbound control to update values

    I have a form that has several unbound fields in it. These fields are used in an update query to update missing information in the database. That all works fine.


    The problem is if there is existing data and the user wants it to be blank.

    I use and iff statement to say if the field is blank, dont update values. If the field is not blank then update the database with its value.

    Based on that is there any way to put something in a field that will clear it. Half of them are date fields and half are not. I tried " " in the date field and that didnt work, however, it does work for the short text fields.

    Is there any way to add something in this date field that will essentially blank it out?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    on the face of it, why not just clear the control so it is null? but it is not at all clear to me what you are asking - suggest provide some example data to illustrate what you are asking.

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Sorry, I cant clear the control because the form is designed to allow the user to just update what they want. I have over 100 fields in the form. The user might update 20 fields but wants the rest of them to stay the same. So when i first created the form i had it set up to clear and then of course you lost all the other data that you were not updating. Very bad.

    So that is why I created the if statement. in the form, if you leave it blank, then it basically updates with the existing value, so in effect, no change. If the field is not blank then it updates with the new value.

    So when a user is on a text field then can put " " and it will make that field blank. They would do this if they want to remove existing data. However, that doesnt work with dates. So instead of " " i was hoping there was maybe some thing like # # that might clear date fields.

    I tried # # and it kind of works. Basically it says " The database didn't update 1 field due to a type conversion failure, blah blah blah" It then clears out the field because it cant read it. But that is confusing to my users so I was hoping there was a cleaner method.

    Thanks

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Simply delete the date from the date unbound date control or set it to Null - A date control will only accept either Null or a Date.

    Then in your IF statement use If IsDate(Me.YourDateControl) then ....
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by tagteam View Post
    <snip> I have over 100 fields in the form. The user might update 20 fields but wants the rest of them to stay the same.
    100 controls??? You have a table with 100 fields?? Doesn't sound normalized....


    Quote Originally Posted by tagteam View Post
    <snip>I tried # # and it kind of works. Basically it says " The database didn't update 1 field due to a type conversion failure, blah blah blah" It then clears out the field because it cant read it.
    The error is because hash mark "#" is a date delimiter. So you must have been trying to store an invalid date in a text or number type field.


    I made an unbound form with 3 unbound controls: "Date1", "Text#" and "Number4".
    I used the double click event to run code to clear the text box controls.

    Code is
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Date1_DblClick(Cancel As Integer)
        ClearCntl ("Date1")
    End Sub
    
    Private Sub Number4_DblClick(Cancel As Integer)
        ClearCntl ("Number4")
    End Sub
    
    Private Sub Text3_DblClick(Cancel As Integer)
        ClearCntl ("Text3")
    End Sub
    
    
    Public Sub ClearCntl(pCntl As String)
        Me.Controls("" & pCntl & "") = Empty
    End Sub
    By double clicking in a control the data is cleared.

  6. #6
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    I dont have 100 fields in the table, just that form. It is used to update 5 different tables at once. The unbound fields start as blank because they are not tied to the table and are unbound. I think Minty may be onto something if there is a way to set a field to Null so that it is not just blank but you are actually setting a null value. Is there a way to attach setting a null value to a button. That way if the user wanted to delete the data in the table (not just the unbound field because that has no bearing on the table at this point) they could click the button and set that field to null and not just blank.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I never allow empty strings in text fields.

    Certainly can set field to Null.

    Me!fieldname = Null
    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.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by tagteam View Post
    I dont have 100 fields in the table, just that form. It is used to update 5 different tables at once. The unbound fields start as blank because they are not tied to the table and are unbound. I think Minty may be onto something if there is a way to set a field to Null so that it is not just blank but you are actually setting a null value. Is there a way to attach setting a null value to a button. That way if the user wanted to delete the data in the table (not just the unbound field because that has no bearing on the table at this point) they could click the button and set that field to null and not just blank.
    Very confusing!! I think it is because of your terminology.

    Just so we are on the same page:

    Tables have FIELDS. There cannot be an "unbound field" in a table. A field in part of the table (an object in the table).
    Forms have CONTROLS. A form can be bound (to a table/query) or unbound. If a form is bound, then the controls ca be bound or unbound.

    It sounds like you have an unbound form with 100 unbound controls on it.
    How are you updating the 5 table? 5 queries? VBA code?


    If you set an unbound control on the form to Empty/NULL, should the field in the table then be set to Empty/NULL?

  9. #9
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Yeah, ok. they are unbound controls on a form. I am using a query. Yes, if the unbound control on the form is set to null then i want it to update the value to empty, whereas now, just leaving the unbound control blank will not change the value.
    I will test what June7 says today and try to use a button with vba behind it to set a particular date unbound control to null and see if that works.
    Thanks,
    Tate

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

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2015, 05:03 PM
  2. Force update of unbound calculated control
    By LillMcGill in forum Forms
    Replies: 7
    Last Post: 04-15-2013, 06:51 PM
  3. Unbound field control Problem
    By justphilip2003 in forum Programming
    Replies: 1
    Last Post: 03-20-2013, 09:10 AM
  4. Update unbound control in report based on if statement
    By echomania in forum Programming
    Replies: 6
    Last Post: 11-23-2012, 11:37 PM
  5. clear field values
    By surrendertoo in forum Queries
    Replies: 0
    Last Post: 02-23-2008, 10:57 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