Solved

Help With this Error 13 on Access 2007 db VBA code

Posted on 2010-09-24
1
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

733 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