Solved

Help With this Error 13 on Access 2007 db VBA code

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

856 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