Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Microsoft Access VBA - Renumbering Function

Posted on 2014-02-28
1
Medium Priority
?
746 Views
Last Modified: 2014-02-28
Hi Experts! I need to develop a function to do the following:

Quote     Line #
12345        1
12345        2
12345        4 <------- change to 3
12345        4 <------- change to 3 (can have duplicate line #'s)
12345        5 <------- change to 4
12345        6 <------- change to 5

I started working on the code but am hitting a wall... I attached a doc with my code thus far.
Sample.docx
0
Comment
Question by:Ei0914
[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
 

Accepted Solution

by:
Ei0914 earned 0 total points
ID: 39895940
I got it to work - here's the function:

Private Sub cmdRenumber_Click()

    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String, strCriteria As String, intQ As Long, intQHold As Long
    Dim i As Integer, chki As Integer
   
    strSQL = "SELECT [Quote-Detail].* FROM [Quote-Detail] ORDER BY [Quote-Detail].Company, [Quote-Detail].Quote, [Quote-Detail].Line;"
   
    Set db = CurrentDb
    Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
    i = 1
    rst.MoveFirst
    Do Until rs
        intQ = rst!Quote
        chki = rst!Line
        strCriteria = "Quote = " & intQ & " and Line = " & chki
        rst.FindFirst strCriteria
        If rst.NoMatch = False Then
            Do Until rst.NoMatch
                rst.Edit
                    rst![LineNew] = i
                rst.Update
                rst.FindNext strCriteria
            Loop
            i = i + 1
        End If
    rst.MoveNext
    If rst.EOF Then GoTo ContinueHere
    intQHold = rst!Quote
    If intQHold <> intQ Then
        i = 1
    End If
    Loop
   
ContinueHere:
    rst.Close
   
    Set rst = Nothing
    Set db = Nothing
   
    MsgBox "Done!"

End Sub
0

Featured Post

Independent Software Vendors: 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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

722 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