• DoCmd.Close: does not work properly

    • This topic has 8 replies, 2 voices, and was last updated 13 years ago.
    Author
    Topic
    #483545

    Friends, I have a form with a field observations. I created a button to open a popup and add
    the observations. In the form I have the popup button to confirm observation.

    In the event the click of a button (popup), I have this code:

    If MsgBox(“Confirm Observation!”, vbYesNo, “Confirm?”) = vbYes Then
    DoCmd.Close

    ‘force refresh of my conten
    Form_fFiltros.combProduto_AfterUpdate

    Else
    CurrentDb.Execute “DELETE * FROM TblObsQualidade WHERE CodObsQualidade = ” & codObs2 & ” ”
    DoCmd.Close

    End If

    With this code, it closes the popup form, the main form is closed, and the popup form is open.
    I’m trying to close the popup form.

    Does anyone have a clue on how I correct?

    Thank you.

    Viewing 7 reply threads
    Author
    Replies
    • #1334788

      Hi Fabio,

      Use the full syntax, specifying the form name too: http://www.blueclaw-db.com/docmd_close_example.htm

      Maybe that will help.

      Regards

    • #1334827

      hi, Rui. Thanks for responding.

      Rui I used the qualified form and it worked. I do not understand why DoCmd.Close (which works to form with the focus).

      I got another popup form with a button to just close with this line of code:

      DoCmd.Close

      The only difference for this new popup and I’m trying to give the user an option to include or not the observation.

      Anyway, my new form popup is now closing properly.

      But, I would like to ask you for help in the following question:

      As I said earlier I’m trying to give an option for the user to confirm or not the record.

      The idea I had was to accomplish this:

      If you choose “no” as a code has been generated with the primary key, my idea was to identify
      the latest code, and delete the record with a DELETE intrução but has no effect.

      I am using this code:

      Private Sub Comando10_Click()
      Dim codObs2 As Integer

      codObs2 = Me.CodObsQualidade

      If MsgBox(“Confirm Observation?”, vbYesNo, “Confirm?”) = vbYes Then
      DoCmd.Close acForm, “FormAddObsQualidade”

      Form_fFiltros.combProduto_AfterUpdate

      Else
      CurrentDb.Execute “DELETE * FROM TblObsQualidade WHERE CodObsQualidade = ” & codObs2 & ” ”
      DoCmd.Close acForm, “FormAddObsQualidade”

      End If

      Honestly, I do not understand why it does not work. (My bank is divided, with bd_be the network and all
      be_fe on other machines).

      Thank you.

    • #1334828

      Fabio,

      Are you calling an AfterUpdate event procedure explicitly? That’s quite uncommon and I wouldn’t think it to be a good practice.

      Have you tried setting a breakpoint ib the CurrentDd.Execute statement and check that the SQL is correct, that is codObs2 has a value? Are there any referential integrity constraints that may be preventing the statement to complete?

    • #1334830

      Rui,

      Yes I’m doing a combo called the explicida. I traded for private audience. This was the only solution I
      when I found to add a note on a subform via popup form, the observation is shown
      immediately when closing the popup, no need to manually update the combo. (I did this with another popup, and now I’m
      also trying with this new, all in the same form, but with different observations).

      See picture1 respect, I am trying to delete the record from the table TblObsQualidade, it is related to
      TblProduto the table, I put referential integrity, but as I’m just trying to delete a record from Table
      TblObsQualidade, I think that referential integrity is not the problem. Still, I took the referential integrity
      but still did not work.

      I had to stop testing the code. See the pictures:

      Image2 código30 (current code of observation time).

      image3 stop, check that the variable’s value is correct.

      The record is not deleted, and also get no error message.

      Thank you.

    • #1334834

      Rui,

      I did a test as follows:

      Stop
      codObs2 = Me.CodObsQualidade
      Stop

      codObs2 = codObs2 – 1
      Stop

      Thus the record is deleted (wrongly, it was only a test).

      I think I need to do some kind of update, to delete the current record, but I do not know how.

      Thank you.

    • #1334902

      Are you trying to delete the current form record?

      If so, try:

      DoCmd.RunCommand acCmdDeleteRecord
    • #1335019

      Rui, Thanks for the tip. I got it, just used Me.Refresh and it worked. Again, thank you

    • #1335039

      Glad that you solved it, Fabio :).

    Viewing 7 reply threads
    Reply To: Reply #1334828 in DoCmd.Close: does not work properly

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel