Solved

Help With this Error 13 on Access 2007 db VBA code

Posted on 2010-09-24
1
295 Views
Last Modified: 2013-12-25
this is the module that gets Error 13, typ mismatch:

Function FindMax2()

    Dim db As DAO.Database
    Dim mx As Integer
    Dim rs As DAO.Recordset
    Dim rsVal As String
   
   
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("UtilityPermit", dbOpenDynaset)
   
    rs.MoveFirst
   
   
    rsVal = rs.Fields("[UtilityPermitNumber]").Value
    mx = Right(rsVal, Len(rsVal) - 8)
   
    Do While Not rs.EOF
        rsVal = rs.Fields("[UtilityPermitNumber]").Value
        If Right(rsVal, Len(rsVal) - 8) > mx Then
        mx = Right(rsVal, Len(rsVal) - 8)
        End If
        rs.MoveNext
    Loop
    FindMax2 = "GRB10-U-" & (mx + 1)
End Function

and this is the utility permit numbers that have been generated from it:

UtilityPermitNumber
GRB10-U-1
GRB10-U-10
GRB10-U-11
GRB10-U-12
GRB10-U-13
GRB10-U-14
GRB10-U-15
GRB10-U-16
GRB10-U-17
GRB10-U-18
GRB10-U-19
GRB10-U-2
GRB10-U-20
GRB10-U-21
GRB10-U-22
GRB10-U-23
GRB10-U-24
GRB10-U-25
GRB10-U-26
GRB10-U-27
GRB10-U-28
GRB10-U-29
GRB10-U-3
GRB10-U-30
GRB10-U-31
GRB10-U-32
GRB10-U-33
GRB10-U-34
GRB10-U-35
GRB10-U-36 - REVISED
GRB10-U-37
GRB10-U-38
GRB10-U-39
GRB10-U-4
GRB10-U-40
GRB10-U-41
GRB10-U-42
GRB10-U-43
GRB10-U-44
GRB10-U-45
GRB10-U-46
GRB10-U-47
GRB10-U-48
GRB10-U-49
GRB10-U-5
GRB10-U-6
GRB10-U-7
GRB10-U-8
GRB10-U-9

at this point it will not add another record.  I get  a Run-tme error '13'.  can anyone help me with this code.  I know it is a minor problem, but I don't know exactly what.  Thanks.
0
Comment
Question by:GarfieldCO
1 Comment
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33754708
Once you hit "GRB10-U-36 - REVISED" you will get a type mismatch: you won't be able to convert that text into an Integer :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now