Affichage des articles dont le libellé est Access VBA Crashes. Afficher tous les articles
Affichage des articles dont le libellé est Access VBA Crashes. Afficher tous les articles

Access VBA Crashes, No Error Codes

jeudi 30 avril 2015

I am having a serious issue with some of my VBA code in my Access front end. It links to a SQL database. Here is my code:
Code:

Private Sub New_Record_Click()
    Dim MySerial As String
    Dim rsCriteria As String
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim Feedback

    Set db = CurrentDb
    Set rs = db.OpenRecordset("FourWire", dbOpenDynaset)

    On Error GoTo ErrorHandlingCode

    MySerial = InputBox("Serial #", "New Part")
    rsCriteria = "[Serial] = '" & MySerial & "'"
    If MySerial = "" Then
        Exit Sub
    End If

    rs.FindFirst rsCriteria                            'Search for existing record
    If rs.NoMatch Then
        'Good, so lets make a new record!
    Else
        Feedback = MsgBox("Record for this part already exists!" & vbCr & "Would you like go to the record?", vbYesNo, "Warning")
        GoTo LoadExistingRecord
    End If

    'Me.FilterOn = False                                        'turn off filter
    DoCmd.GoToRecord , , acNewRec
    [Serial_FourWire].value = MySerial
    DoCmd.Requery
    rsCriteria = "[Serial] = '" & MySerial & "'"
    'Me.[Black_Blue].SetFocus

    rs.Close

    DoCmd.Echo False
    Forms("Four_Wire_Test").Recordset.FindFirst rsCriteria
    If Forms("Four_Wire_Test").Recordset.NoMatch Then
        MsgBox "Could not find record just created! Contact your administrator."
    End If
    DoCmd.Echo True

    Exit Sub

LoadExistingRecord:
    If Feedback = vbYes Then
        Forms("Four_Wire_Test").Recordset.FindFirst rsCriteria    'User clicked "Yes"
        Me.[Black_Blue].SetFocus
    Else
        'Just Quit                                              'User clicked "No"
    End If

    Exit Sub

ErrorHandlingCode:
  Dim strError As String
  Dim errLoop As Error

  For Each errLoop In Errors
        With errLoop
        strError = _
          "Error #" & .Number & vbCr
        strError = strError & _
          "  " & .Description & vbCr
        strError = strError & _
          "  (Source: " & .Source & ")" & vbCr
        strError = strError & _
          "Press F1 to see topic " & .HelpContext & vbCr
        strError = strError & _
          "  in the file " & .HelpFile & "."
    End With
    MsgBox strError
  Next
End Sub

I have managed to isolate the crash, which entirely takes down Access 2007, without a fault. The line is:
Code:

    Forms("Four_Wire_Test").Recordset.FindFirst rsCriteria
One note is that I have used this code successfully before in other places of my front end. "rsCritera" is equal to "[Serial] = '1234567'". I have confirmed that "1234567" exists in the table "FourWire".

Does anyone have any recommendations as to what I am doing? Why access is just crashing and not able to give me a fault code or anything? Any help is much appreciated.
:banghead:
Access VBA Crashes, No Error Codes

Labels