Solved

Microsoft Access VBA - Renumbering Function

Posted on 2014-02-28
1
720 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

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