Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2010
    Posts
    3

    Unanswered: Creating a command button that will add a date to my record

    I am a novice who understands the database concepts. I have a form with a sub form that uses a date in the sub form. I want to add a command button that will add a date record in the sub form by me only pressing the button. Can someone help with the right code to accomplish this task.

    I'm tracking multiple forms that come in for the same user but on different dates. Everytime a form comes in I want to press the button and that date shows up on that record.

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Not sure I fully understand when you say "add a date record". If you want to populate the value of a field (hopefully a date type if saving dates) in the subform with a date value, you can use code as such:

    Forms!MyMainFormName!MySubFormName!MyDateField = Date()

    When it comes to date fields, in almost all my date tables I will have a 'DateEntered' field (along with an 'EnteredBy' field). I then set the default value (on the form or subform) of this field to =Date() or =Now() so that whenever a new record is added, it defaults this value to the current date or date/time. For the 'EnteredBy' field, I set the default value using the getuser() method (ie. =getuser()). This then tells me 'who' entered that record and when. See the code bank if you are interested in the getuser() function which automatically grabs the user's loginID.

    But I 'think' the answer you are looking for is geared towards how to populate a field value on a subform. I put a reference to the subform itself as the above example portrays. - again, Forms!MyMainFormName!MySubformName!MyDateFieldName = Date().

    If you meant adding a new record itself in the subform by pushing a button on the main form, you can use code as such:

    Forms!MyMainFormName!MySubformName.setfocus
    Docmd.gotorecord,,acnewrec
    Forms!MyMainFormName!MySubformName!MyDateFieldName = Date()
    ....(and code to populate other subform fields.)
    Last edited by pkstormy; 08-01-10 at 14:25.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Jul 2010
    Posts
    3
    Thank you for your speedy reply. I have tried to understand what you are saying, and I do to a certain point but I really dont lmpw where to place this code that you are speaking of.

    If you could explain it to me I would greatly appreciate it. Also I am uploading my database if you can look at it and give me some pointers. I will continue to try and understand what you have expllained to me until I hear back from you. thank you so much for your help.
    Attached Files Attached Files
    Last edited by rockman333; 08-02-10 at 03:54.

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Sorry about that rocman333. Let's try this again.

    Looking at your example, it looks like you have a separate table in which you want to do some kind of 'received' tracking. I'm confused on the 35-1 Received table. This doesn't really server any purpose and won't help you in any way. What do you want to accomplish with this table? Since it doesn't link to your other table via any relationship, I don't really see any value with it.

    If you want to track when a record is added to the EmployeeRecords table, you can simply add the 'Date Received' field into your EmployeeRecords table instead (but remove spaces in the name - spaces are killers when it comes to any coding) and set the default value of this field either in the table design (or on the form) to =Now(). This will automatically enter the date/time the record was inserted. Is that what you want to accomplish - knowing when each EmployeeRecords record is added to the table? By setting the default value, you wouldn't need any kind of button on the form to insert this value.
    Last edited by pkstormy; 08-02-10 at 07:17.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Jul 2010
    Posts
    3
    I should have completed the relationship between the Main table and the Date table. What is going on is for my organization 1 person can fax in multiple request of time. I want to be able to have a one-Many format so when Joe sends in multiple documents on different days I can track the multiple dates for each record.

    That why I wanted a button so when I pull up an employee, when I push the buton, what ever that current date was it would be like stamping the date on our record. Because I did not send you a copy with a formed relationship you would not have know what I am trying to do.

    Thank you for really trying to help me with this one. Can you suggest any type of training or reading material. I'm so interested in this stuff but no formal training. Know what I want just not how to get it.

    Thanks in advanced.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •