Solved

Help With this Error 13 on Access 2007 db VBA code

Posted on 2010-09-24
1
294 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

746 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

15 Experts available now in Live!

Get 1:1 Help Now