Results 1 to 11 of 11
  1. #1
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142

    Save the Record and the clear the form for next entry

    Hi
    I am trying to save a record in the form and once I click the save button. Data is saved to the table. and the form is not cleared for the next entry.

    Please help me with this.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    records save automatically, but to move to the new rec, add:

    DoCmd.GoToRecord , , acNewRec

  3. #3
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I tried that. It is not working. My controls are unbound. I placed the above code in the after update event of the save button.
    Or am I placing the code at the wrong place?

    Here is the code:

    Private Sub ADD_Click()
    Dim rs As Recordset
    On Error GoTo ErrHandler
    If MsgBox("Do you want to add the record.", vbQuestion + vbYesNo, "Add New Record?") = vbYes Then
    Set rs = CurrentDb.OpenRecordset("Copy Of Projects_T", dbOpenDynaset, dbAppendOnly)
    rs.AddNew
    rs.Fields("Element").Value = Me.Element.Value
    rs.Fields("ProjectName").Value = Me.ProjectName.Value
    rs.Fields("WBS").Value = Me.WBS.Value
    rs.Fields("Status").Value = Me.Status.Value
    rs.Fields("DateClosed").Value = Me.DateClosed.Value
    rs.Fields("Category").Value = Me.Category.Value
    rs.Fields("Closed").Value = Me.Closed.Value


    rs.Update
    MsgBox "Record saved.", vbInformation, "Record Saved"
    End If
    Exit Sub
    DoCmd.GoToRecord , , acNewRec
    ErrHandler:
    MsgBox Err.Description, vbExclamation, "Error Occurred"
    End Sub


    Quote Originally Posted by ranman256 View Post
    records save automatically, but to move to the new rec, add:

    DoCmd.GoToRecord , , acNewRec

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    The DoCmd.GoToRecord will never be executed, as you have an Exit Sub right before it.

    In any case, that might cause an error anyway if the form is unbound (in which case remove the line).
    If the form is unbound, you will need to blank out all the unbound fields to make them empty. You can add that code right before the Exit Sub.

  5. #5
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I placed the DoCmd.GoToRecord , , acNewRec before the exit sub. Its not working.

    Quote Originally Posted by davegri View Post
    The DoCmd.GoToRecord will never be executed, as you have an Exit Sub right before it.

    In any case, that might cause an error anyway if the form is unbound (in which case remove the line).
    If the form is unbound, you will need to blank out all the unbound fields to make them empty. You can add that code right before the Exit Sub.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    Its not working.
    Tell me more.

  7. #7
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I have attached the Db for your reference.
    please go to the Add Employees form. and the second tab: "ADD New Employee".
    Once you enter all the data, click save button. the data is not cleared for the next record.

    Quote Originally Posted by davegri View Post
    Tell me more.
    Attached Files Attached Files

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    As I mentioned in post #4, you have to blank out the fields...
    Code:
        MsgBox "Record saved.", vbInformation, "Record Saved"
        LastName = Null
        FirstName = Null
        UserLogID = Null
        EmailAddress = Null
        Company = Null
        SubContractor = Null
        PositionTitle = Null
        OfficeLocation = Null
        MobileNumber = Null
        BusinessTelephone = Null
        ContractNumber = Null
        TaskOrder = Null
        UDF2 = Null
        UDF3 = Null
      End If
     'DoCmd.GoToRecord , , acNewRec
      Exit Sub

  9. #9
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Sorry I missed that.
    Its working now!
    Thank you tons!![

    QUOTE=davegri;404710]As I mentioned in post #4, you have to blank out the fields...
    Code:
        MsgBox "Record saved.", vbInformation, "Record Saved"
        LastName = Null
        FirstName = Null
        UserLogID = Null
        EmailAddress = Null
        Company = Null
        SubContractor = Null
        PositionTitle = Null
        OfficeLocation = Null
        MobileNumber = Null
        BusinessTelephone = Null
        ContractNumber = Null
        TaskOrder = Null
        UDF2 = Null
        UDF3 = Null
      End If
     'DoCmd.GoToRecord , , acNewRec
      Exit Sub
    [/QUOTE]

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    BTW, if you want the 'Refresh Employee List' button to show everyone, change its code to this:
    Code:
    Private Sub Command48_Click()
        sRowsource = "SELECT [Copy Of Employee_T].FullName, [Copy Of Employee_T].EmployeeID, [Copy Of Employee_T].deployed  FROM [Copy Of Employee_T] "
        lstEmployee.RowSource = sRowsource
        txtSearch = Null
        lstEmployee.Requery
    End Sub

  11. #11
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Thank you so much!!
    I was trying to figure that out.
    Thanks again!!
    Quote Originally Posted by davegri View Post
    BTW, if you want the 'Refresh Employee List' button to show everyone, change its code to this:
    Code:
    Private Sub Command48_Click()
        sRowsource = "SELECT [Copy Of Employee_T].FullName, [Copy Of Employee_T].EmployeeID, [Copy Of Employee_T].deployed  FROM [Copy Of Employee_T] "
        lstEmployee.RowSource = sRowsource
        txtSearch = Null
        lstEmployee.Requery
    End Sub

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

Similar Threads

  1. Replies: 4
    Last Post: 01-03-2018, 11:12 PM
  2. Save some text fields and clear others
    By whisp0214 in forum Forms
    Replies: 9
    Last Post: 10-25-2017, 03:48 PM
  3. A Better way to Save & Proceed to New Entry Form?
    By nick404 in forum Programming
    Replies: 3
    Last Post: 06-13-2015, 07:37 AM
  4. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  5. Replies: 2
    Last Post: 10-03-2012, 02:58 AM

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