Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Posts
    110

    Unanswered: Data type mismatch error

    I have a table with a long integer autonumber primary key. I have built a form with a text box as well as a button. The idea is that a user inputs a long integer in the text box and deletes all relevant records by pressing the button.
    The code I have written is :

    ' Returns 1 if repair exists in table EPISKEYH
    Private Function Find_repair_existence(lngKwdikos_episkeyhs As Long)
    Dim strSelect As String
    Dim rs As Recordset
    Dim intRecordCount As Integer

    strSelect = "Select * FROM EPISKEYH WHERE Kwdikos_episkeyhs ='" & lngKwdikos_episkeyhs & "'"
    Set rs = CurrentDb.OpenRecordset(strSelect)

    ' Error handling for fre (Find_repair existence)
    On Error GoTo No_Rec_fre
    rs.MoveLast
    On Error GoTo 0
    intRecordCount = rs.RecordCount
    GoTo Continue_Sub_fre

    No_Rec_fre:
    On Error GoTo 0
    intRecordCount = 0

    Continue_Sub_fre:
    Find_repair_existence = intRecordCount

    End Function

    Private Sub btnDelete_Click()
    Dim strSelect As String
    Dim rsEpiskeyes As Recordset
    Dim intRecordCount As Integer, intSafety As Integer

    If Not IsNull(Me.Kwdikos_episkeyhs) Then

    ' Firstly, check to check whether repair exists in table EPISKEYH
    If Find_repair_existence(CLng(Me.Kwdikos_episkeyhs)) = 0 Then
    MsgBox ("Ανύπαρκτος κωδικός!")
    Exit Sub
    End If

    ' Select string, typecast variant value of text box to Integer before comparing
    ' Checks to see whether the repair has any references to table ANTALLAKTIKA
    ' If yes, then do not permit deletion

    strSelect = "Select * From ANTALLAKTIKA WHERE Kwdikos_episkeyhs ='" & CInt(Me.Kwdikos_episkeyhs) & "'"
    Set rsEpiskeyes = CurrentDb.OpenRecordset(strSelect)

    On Error GoTo No_Rec
    rsEpiskeyes.MoveLast
    On Error GoTo 0
    intRecordCount = rsEpiskeyes.RecordCount
    GoTo Continue_Sub

    No_Rec:
    On Error GoTo 0
    intRecordCount = 0

    Continue_Sub:
    If intRecordCount = 0 Then
    intSafety = MsgBox("Είσαι σίγουρος για τη διαγραφή; ", vbOKCancel)
    If (intSafety = vbCancel) Then
    MsgBox ("Διαγραφή ακυρώθηκε!")
    Exit Sub
    End If

    strSelect = "Delete FROM EPISKEYH WHERE Kwdikos_episkeyhs ='" & CLng(Me.Kwdikos_episkeyhs) & "'"
    CurrentDb.Execute (strSelect)
    MsgBox ("Επιτυχής διαγραφή!")
    DoCmd.Close acDefault
    Else
    MsgBox ("Δεν γίνεται να διαγραφεί η επισκευή, διότι υπάρχουν συσχετιζόμενα ανταλλακτικά!")
    End If
    Else
    MsgBox ("Συμπληρώστε τον κωδικό της επισκευής πρώτα!")
    End If

    End Sub


    All OpenRecordset statements fail with error. Am I missing something about the typecasting?

    Any help would be appreciated

    George Papadopoulos
    Electronic Engineer
    Attached Thumbnails Attached Thumbnails flip-lid.gif  

  2. #2
    Join Date
    Mar 2004
    Posts
    118
    yea:


    strSelect = "Select * FROM EPISKEYH WHERE Kwdikos_episkeyhs ='" & lngKwdikos_episkeyhs & "'"

    Needs to be

    strSelect = "Select * FROM EPISKEYH WHERE Kwdikos_episkeyhs ='" & CStr(lngKwdikos_episkeyhs) & "'"

Posting Permissions

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