VBA Code for Exit Button RRS feed

  • Question

  • I have created the following code to run on an Exit button for a form.

    Private Sub cmdExit_Click()
    DoCmd.SetWarnings False
    On Error Resume Next

    DoCmd.OpenQuery "ApplicationAccesswithoutUserApps", acViewNormal, acReadOnly ' run the Application Without User Query

    DoCmd.OpenQuery "AppendUserApps", acViewNormal, acReadOnly ' run the AppendUserApps Query

    DoCmd.Close acForm, "ApplicationAccess", acSaveNo 'Close the Application Access Form

    DoCmd.SetWarnings True
    End Sub

    The problem is the query is creating a new record in the sub-form for the first record in the database.

    I have a form with a sub-form.  The main form is for viewing current records or adding a new record and the sub-form shows all currently related records for a user.

    The form has UserName, Department, Application, Supervisor, Removal Date fields.

    The sub-form has UserName and Application fields.

    Why is the Exit button code creating a new blank record for the first record in my main table?

    Saturday, June 25, 2016 1:48 AM

All replies

  • Hi. Looks like the query "AppendUserApps" might be adding the record for you. Do you have to run it when closing the form? If so, you might review the query to make sure it's doing what it's supposed to do. Just a thought...
    Saturday, June 25, 2016 2:14 AM
  • Hi LC-Mike,

    did you make a test with your query that creating issue?

    if not check it first.

    from the above mentioned code we are not able to find any problem that you had describe above.

    we need to see the query.

    so it is also better that you post your query here so that other member can also see your query and if they find some problem in that they can suggest you to make some change to get your desired result.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 27, 2016 12:57 AM