Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2013

    Unanswered: Runtime Error 13

    We use a sql database which keeps a record of all the projects the company is/has been working on. The database has been set up to automatically create a unique, sequential project number for a new project when you either press a button or double click in the blank row at the bottom of the form. All has been working fine for ages but now all of a sudden when we try to automatically create a new project number we are getting a Runtime Error 13 Type Mismatch. The problem is the guy who developed this database no longer works for the company and I don't know anything about visual basic.

    Can anyone help me to work out what the problem in the code below is? The line in the code that is highlighted when I click on 'debug' is in bold.

    Private Sub Project_ID_DblClick(Cancel As Integer)
    Dim strLatestProjID As String
    Dim strNewProjectID As String
    Dim intID As Integer

    Dim con As ADODB.Connection
    Dim rst As ADODB.Recordset
    Set con = CurrentProject.Connection
    Set rst = New ADODB.Recordset

    rst.Open "SELECT TOP 1 [Project_ID] FROM [Work Codes] ORDER BY ID DESC", con, adOpenForwardOnly, adLockOptimistic

    If Not rst.EOF And Not rst.BOF Then
    strLatestProjID = rst("Project_ID").Value
    End If

    Set rst = Nothing
    Set con = Nothing

    If strLatestProjID <> "" Then
    strLatestProjID = Right(strLatestProjID, 4)
    intID = strLatestProjID + 1
    strNewProjectID = "A" & intID
    End If

    DoCmd.GoToRecord , , acNewRec, 0
    Me!Project_ID.Value = strNewProjectID
    End Sub

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    strLatestProjID is defined as string
    Dim strLatestProjID As String
    yet you are trying to use a string variable as a number
    intID = strLatestProjID + 1
    the solution
    expressly convert the string value using say the CINT function
    or don't use the string datatype at all, and declare it as the same datatype as the underlying column

    Im guessing the code is fine when it finds an exisiting Project_ID, but because you are using a string vdatatype the code gets upset whn there is no Project_ID found and you then try to add 1 to NULL

    "" isn't the same as NULL and you cannot compare a value to NULL you need to use the ISNULL function
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    This could also be caused by someone simply making a mistake keying in a value. Your code will pop this error if the 4 right-most characters aren't numeric or at least able to be interpreted as numeric.




    will work without a problem, but




    will pop Error 13. If the number is usually/always generated automatically, someone could have accidentally started deleting it, realized what they were doing, and tried to correct it, inputting an alpha character by mistake.

    Linq ;0)>
    Last edited by Missinglinq; 02-11-13 at 19:08.
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Feb 2013

    Runtime Error 13

    Thanks for your replys.

    So, how do I rewrite the code? As I said I don't know anything about visual basic and don't understand the code, but I need to try and fix the problem!

Posting Permissions

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