Results 1 to 3 of 3
  1. #1
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81

    Question Continuous Forms error when trying to add record

    Hi,


    I setup a very basic form to show a list of tasks ("to-do" items) from a table : tblTask_Listing.
    The form is setup as a Continous Form; it contains the following fields from the aforementioned table:
    TASK_DESCRIPTION (Short Text), TASK_ADDED_BY (Short Text), TASK_DATE (Date), TASK_COMPLETED (True/False).
    There's also a TASK_ID field in the table which is the Primary Key (AutoNumber), though I'm not actually displaying that field on the form.

    Instead of users needing to manually populate the TASK_ADDED_BY / TASK_DATE fields, I want those to automatically populate with their UserID and Today's Date, respectively. The controls associated with those 2 fields are simply "txtUser" and "txtDate".
    Thus, I placed the below code in the "After Update" event.
    When I add a new record at the bottom of the form, those 2 controls *do* indeed update with UserID + Date, as intended.. but when closing out of the form, I keep receiving an error message which states, "You can't save this record at this time. Microsoft Access may have encountered an error when trying to save a record (etc.)"

    So clearly there's something that I'm missing in the code that it doesn't like. If I remove the After Update event/code, the form works fine - but obviously the UserID and Date fields must be manually populated which is what I'm trying to avoid.

    Any help would be appreciated. Thanks!

    Code:
    Private Sub Form_AfterUpdate()
    
    
    Dim strUserID As String
    Dim strDate As String
    
    
    strUserID = Environ("Username")
    strDate = Format(Date, "mm/dd/yyyy")
    
    
    Me!txtUser = strUserID
    Me!txtDate = strDate
    
    
    End Sub

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    you need to use the form beforeupdate event and your code is trying to assign a string to the date field

    all you need is


    Me.txtUser =Environ("Username")
    Me.txtDate = Date()

    note that dates are stored as numbers, not formatted as you see them

  3. #3
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Thanks Ajax - that worked perfectly. I did try the "BeforeUpdate" event yesterday to no avail, but it must have been due to the fact that I was trying to assign a string variable to my date field.
    Sometimes I'm so dense that it's astounding.. :-\

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

Similar Threads

  1. Continuous forms updating all
    By musclecarlover07 in forum Access
    Replies: 15
    Last Post: 03-11-2014, 10:48 AM
  2. Replies: 12
    Last Post: 10-31-2013, 02:35 AM
  3. No Current Record error - Continuous Form
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 08-25-2012, 08:43 AM
  4. Suppress new record on continuous forms
    By ajetrumpet in forum Forms
    Replies: 0
    Last Post: 09-07-2010, 09:30 PM
  5. Replies: 2
    Last Post: 10-16-2009, 02:47 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