Results 1 to 15 of 15
  1. #1
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53

    Overwriting given Value in From with default value

    Hello eveyone,

    I created a simple from links to a table, when the form open it gives me the values for that record.
    I need to overwrite the values in a field "Data Created" to always be the current date.

    I thought I could just put in the default value ""= Date()"" but that didn't work. It doesn't overwrite the value already in the record.

    I bet is something super simple, but I have been struggling with this for hours now

    Thanks so much
    Chico

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    As you have discovered, the default value *only* applies when there is not current value in a field. I'm surprised you want a Field named "Data Created" to change from it's initial value but TimeStamps (which is another name for what you are doing) are usually implemented in the BeforeUpdate event of the form. That way it only changes when some piece of data changes on the form.
    Me![Data Created] = Date()
    ...would go into the BeforeUpdate event of the Form.

  3. #3
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53
    Thanks for the replay, I should have put a bit more information.
    I created a bottom with a macro to open a form and duplicate a record.
    So I select some record, press that bottom and a form pops up with all the values for that record but already as a new record. Them I can change just what I want instead of having to populate all the values on every field.
    that's way I need to have the date created filed as Date() because is a new record.

    Unfortunately that code you gave me didn't work.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You are changing values on the "pop up" form and the code I gave you doesn't work? Can you post the code you used please? It will not change the field until the record is saved. Did you go back and check the record?

  5. #5
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53
    Sorry I was doing a mistake and putting the code not on the form properties but on that field properties.

    However it also din't work, it just doesn't create the new record.
    I think a work around would be to have an unbound box with the default value.

    But them how do I tell that what ever is put in that unbound box goes in a field on a table?
    I need this for other things to and I can't find a way o create unbound box to populate specific fields in a table with whatever is in that box.
    Can you help me out with this, I bet is Access 101 but I'm really struggling with it.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Can you show us what the Button is using to open the next form?

  7. #7
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53
    Hi, Sorry for the delay.

    I attached the entire access File
    Please keep in mind that until this week I didn't even know what access was and never even touch a vbscript or any other scripting language!!

    What I'm trying to do is duplicate a record with the date set automatically for the date created.
    If you think you have the time and patience I will be eternally grateful if you can take a look at the file and see whats the problem.

    I Still have alot to do.
    I need to create a history of changes when editing a record, have now idea how to go at that.
    And fix the problem in the navigation form that doesn't really work.

    I bet what is taking me a hole day will only take 5 min to a pro.

    Let me know what you think and what changes you would do.
    Thanks so much in advance.
    Attached Files Attached Files

  8. #8
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    See post #12 in the other thread you started.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm going to be honest here. This is the first time I tried to do anything with a Macro and I frankly do not like them. What I can do in 30 seconds in code I could not do in 30 minutes with those Macros. Maybe someone that has experience with Macros will jump in here.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    BTW, I did notice the code I supplied did work as I expected when the record is saved.

  11. #11
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53
    I managed to do it, maybe a huge work around but It is working.
    I created a update query to update the table with the value of an unbound text box with the default value.

    then created a function with this code

    Code:
            DoCmd.SetWarnings False
            DoCmd.OpenQuery "Query_Name"
        DoCmd.SetWarnings True
            Me.Requery
    and in the macro I call the function.

    I agree, macros aren't the way. but I was using the bottom wizard and changing the macros it gives.
    I'm new to this, for me writing code takes forever. Specially testing if it work.

    How did you manage to do it with the code you wrote?
    Can you save the file and attach it here so I can see?

    Thanks so much for all your help.
    Without forums like this and people like you it would be impossible for guys like me to start on this adventure of scripting

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    For a VBA procedure:

    In the event property select [Event Procedure]. Click the ellipses (...) to open the VBA editor. Type code in the procedure.

    CurrentDb.Execute "UPDATE Part_Database SET Date_Created=Date();"

    SetWarnings will not be necessary with that method. That SQL will modify every record in the table. If you want to modify particular record(s) then include filter criteria in the SQL.

    If you just want to modify the current record on form, then the UPDATE is not needed.

    Me.Date_Created = Date()

    The real trick is figuring out what event to put code in.
    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.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Can you describe for me the reason for duplicating an existing record rather than just creating a new one?

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is it simply to save some typing for the user?

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Here's a link you will want to read as well: http://access.mvps.org/access/lookupfields.htm

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

Similar Threads

  1. Overwriting Records?
    By DataUser in forum Access
    Replies: 8
    Last Post: 10-10-2011, 05:58 PM
  2. Linking Workbook and Overwriting Excel File
    By Atheron in forum Import/Export Data
    Replies: 2
    Last Post: 10-08-2011, 03:44 PM
  3. Overwriting Calculated Field
    By sidewayzalex in forum Forms
    Replies: 2
    Last Post: 08-24-2011, 05:52 AM
  4. Set default value
    By accessnewb in forum Programming
    Replies: 3
    Last Post: 08-17-2011, 06:24 PM
  5. overwriting table rows
    By VickyC in forum Forms
    Replies: 2
    Last Post: 09-23-2010, 07:58 AM

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