Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts

    DoCmd.Close: does not work properly

    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.
    Last edited by fabiobarreto10; 2012-05-31 at 13:44.

  2. #2
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    10,285
    Thanks
    130
    Thanked 1,153 Times in 1,062 Posts
    Hi Fabio,

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

    M
    aybe that will help.

    Regards

  3. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-06-01)

  4. #3
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts
    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.
    Last edited by fabiobarreto10; 2012-06-01 at 10:49.

  5. #4
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    10,285
    Thanks
    130
    Thanked 1,153 Times in 1,062 Posts
    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?

  6. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-06-01)

  7. #5
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts
    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.
    Attached Files Attached Files

  8. #6
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts
    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.

  9. #7
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    10,285
    Thanks
    130
    Thanked 1,153 Times in 1,062 Posts
    Are you trying to delete the current form record?

    If so, try:
    DoCmd.RunCommand acCmdDeleteRecord

  10. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-06-02)

  11. #8
    2 Star Lounger
    Join Date
    Jan 2012
    Posts
    155
    Thanks
    118
    Thanked 0 Times in 0 Posts
    Rui, Thanks for the tip. I got it, just used Me.Refresh and it worked. Again, thank you

  12. #9
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    10,285
    Thanks
    130
    Thanked 1,153 Times in 1,062 Posts
    Glad that you solved it, Fabio .

  13. The Following User Says Thank You to ruirib For This Useful Post:

    fabiobarreto10 (2012-06-02)

Posting Permissions

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