View Single Post
  #1 (permalink)  
Old July 16th, 2003, 09:20 AM
mikeceee mikeceee is offline
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning Visual Basic 6 Database Programming

Below is a chunk of code that I'm running from chapter 6.

-------------------------------------------------------------
Private Sub cmdButton_Click(Index As Integer)
  Static vMyBookMark As Variant
  Select Case Index 'what is the value of the key pressed?
    Case cmdMoveFirst
    Case cmdMovePrevious
    Case cmdMoveNext
    Case cmdMoveLast
    Case cmdAddNew
    Case cmdEdit
      With Data1.Recordset
        If (.EditMode = dbEditNone) Then
          vMyBookMark = .Bookmark
          .Edit
          Call updateButtons
          lblRecordCount = "Editing"
        End If
      End With
    Case cmdSave
    Case cmdDelete
    Case cmdUndo
    Case cmdFind
    Case cmdDone
  End Select
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  Dim iMessage As Integer

  If (Data1.Recordset.EditMode <> dbEditNone) Then
    iMessage = MsgBox("You must complete editing the _
     current record", vbInformation, App.EXEName)
    Cancel = True
  End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set frmPublishers = Nothing
End Sub

-------------------------------------------------------------
The code is suppose to prevent the user from closing down the form or window when they are in the middle of editing a record. The problem is the expression "Data1.Recordset.EditMode <> dbEditNone" in the if statement never becomes true like the book says it should. The Data1.Recordset.EditMode = vbEditInProgress after the Case cmdEdit runs the .Edit method. But as soon as the code reaches Private Sub Form_QueryUnload the Data1.Recordset.EditMode changes to vbEditNone!

Thanks in advance,
Mike