Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2013
    Posts
    19

    Unanswered: How do I handle the save procedure?

    I have a form (Equipment inventory) – and a subform (equipment maintenance contracts).

    I use the subform to create/update contracts. When the user clicks the save button, a flag turns on to let system know the user just wants to save the record. If I don’t do it like this, the before upddate event asks (after hitting the save button) “you made some changes, want to save them?”, which only ought to happen when the user does not click the save button (closing the form or going to a different record).

    The problem is the before update procedure does its checking, but does not go back to continue the save procedure. It seems that I have to click the save button twice to do first time, the checking and the second time the save. I do not think this is the right way to do these events, but I can’t seem to find the proper way. Could it be because I am using the subform, but the Save button is on the main form? Does that make a difference?

    This is my code on the subform:
    Private Sub Form_BeforeUpdate(Cancel As Integer)

    On Error GoTo Err_BeforeUpdate

    If Me.Dirty Then 'If form has new data...
    If GSaveMsg = True Then 'and user clicked the save button...
    MsgBox "Saving record...", vbInformation, "Save record"
    *** here it should go back to continue with the Save procedure ***
    Else
    If MsgBox("You made some changes, do you want to save them?", _
    vbYesNo + vbQuestion, "Save Record") = vbNo Then
    Me.Undo
    MsgBox "Information discarded...", vbInformation, "Record updating"
    End If
    End If
    End If

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what happens if you step through the code?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2013
    Posts
    19
    When I step through the code after I hit the save button, it hits the if it's dirty and flag is on - goes through that side, sees that I hit save button, but does not comeback to continue with the save procedure. I wish I could send it to the save proc to continue with the rest of the steps. The record gets saved somehow.

    If I want to close the form without saving, it asks "you made some changes, do you want to save them? If I say no, it "undoes" the changes. this part works fine. It is after hitting save that's not really hitting all the steps.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I've indented your code to make it a bit easier to read, but I have a question...
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
     On Error GoTo Err_BeforeUpdate
    
     If Me.Dirty Then 'If form has new data...
        If GSaveMsg = True Then 'and user clicked the save button...
           MsgBox "Saving record...", vbInformation, "Save record"
     *** here it should go back to continue with the Save procedure ***
        Else
           If MsgBox("You made some changes, do you want to save them?", _
              vbYesNo + vbQuestion, "Save Record") = vbNo Then
                 Me.Undo
                 MsgBox "Information discarded...", vbInformation, "Record updating"
           End If
        End If
     End If
    What were you thinking would happen at the red/bold line? Is that a note to the coder to have them make a change, an assumption about the user behavior (which is NEVER a good idea), or what you think the code will do on its own?

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  5. #5
    Join Date
    Jul 2013
    Posts
    19
    Thanks Pat for your answer.

    At the red bold line I wanted to signal you that that's where the save procedure should continue. Am I wrong on this?

    This is how I understand this flow: If I hit the save button, it goes to the before update, check a few things. If everything is fine, continue with save proc.

  6. #6
    Join Date
    Oct 2013
    Posts
    1
    Error enumerating daa servers. Enumerator reports 'Unspecified error

    this arrear is generated why ? can you help me
    because i am working on Visual Basic 6.0 with sql server 2000 for connectivity

  7. #7
    Join Date
    Jul 2013
    Posts
    19

    Save Procedure

    I think you are sending this to me by mistake. Sorry I can't help you. I am trying to get answers myself.

Posting Permissions

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