Consulting

Results 1 to 3 of 3

Thread: Solved: Error Handler Routine Problem

  1. #1
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location

    Solved: Error Handler Routine Problem

    Hi,

    I've setup an error handler routine that always runs.
    I can't work out why. I'm using a shared workbook.
    When the workbook is saved if someone else is saving the workbook at the same time then the error handler routine will run. However the routine always runs. I've unshared the workbook and tried saving it by myself and it generates the error.

    Any suggestions?

    [vba]Private Sub cmdUpdate_Click()
    ' Check to see if Who Called has been completed
    If Trim(Me.cboWhoCalled.Value) = "" Then
    Me.cboWhoCalled.SetFocus
    MsgBox "Please complete the Who Called field!"
    Exit Sub
    End If

    ' Check to see if Nature Of Call has been completed
    If Trim(Me.cboReason.Value) = "" Then
    Me.cboReason.SetFocus
    MsgBox "Please complete the Nature Of Call field!"
    Exit Sub
    End If

    Call SendGeneralEmail

    ActiveWorkbook.Save

    On Error GoTo ErrHandler


    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("InboundData")

    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row

    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.txtDate.Value
    ws.Cells(iRow, 2).Value = Me.txtCM.Value
    ws.Cells(iRow, 3).Value = Me.cboWhoCalled.Value
    ws.Cells(iRow, 4).Value = Me.txtDealerNo.Value
    ws.Cells(iRow, 5).Value = Me.txtContact.Value
    ws.Cells(iRow, 6).Value = Me.txtDealerName.Value
    ws.Cells(iRow, 7).Value = Me.cboScheme.Value
    ws.Cells(iRow, 8).Value = Me.cboReason.Value
    ws.Cells(iRow, 9).Value = Me.txtComments.Value
    ws.Cells(iRow, 10).Value = Me.cboSubject.Value

    'clear the data
    Me.txtDate.Value = Format(Date, "yyyy/mm/dd")
    Me.txtCM.Value = Application.UserName
    Me.cboWhoCalled.Value = ""
    Me.txtContact.Value = ""
    Me.txtDealerNo.Value = ""
    Me.txtDealerName.Value = ""
    Me.cboScheme.Value = ""
    Me.cboReason.Value = ""
    Me.txtComments.Value = ""
    Me.cboSubject.Value = ""
    Me.txtCM.SetFocus

    Unload Me

    ErrHandler:
    MsgBox "Another user is trying to save the workbook. Automatically retrying in 5 seconds."
    Application.Wait Now + TimeValue("0:00:05")
    ActiveWorkbook.Save
    Resume Next

    End Sub[/vba]

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Isn't it just a missing

    [vba]

    Exit Sub
    [/vba]

    just prior to the ErrHandler label?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Quote Originally Posted by xld
    Isn't it just a missing

    [vba]

    Exit Sub
    [/vba]

    just prior to the ErrHandler label?
    My utter noobishness show again!!

    Thanks xld
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

Posting Permissions

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