Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:43:06+00:00 2026-05-29T09:43:06+00:00

Sorry the title is not very descriptive but it is a tricky problem to

  • 0

Sorry the title is not very descriptive but it is a tricky problem to word.

I have some data, about 200 or more rows of it, and each row has a PacketID, so several rows belong in the same packet. What I need to do, is convert all the PacketIDs from (Example – BDFD-2) to just a number (Example – 1) so all the entries with a packet identifier x need to have a packet identifier of say 3. Is there an SQL query that can do this? Or do I just have to go through manually.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:43:07+00:00Added an answer on May 29, 2026 at 9:43 am

    You asked about a query. I wrote a quick VBA procedure instead just because it was so easy. But I’m unsure whether it is appropriate for your situation.

    I created tblPackets with a numeric column for new_PacketID. I hoped that will make it clearer to see what’s going on. If you truly need to replace PacketID with the new number, you can alter the procedure to store CStr(lngPacketID) to that text field. So this is the sample data I started with:

    PacketID new_PacketID packet_data
    BDFD-2                a
    R2D2-22               aa
    BDFD-2                b
    R2D2-22               bb
    EMC2-0                aaa
    EMC2-0                bbb
    

    And this is the table after running the procedure.

    PacketID new_PacketID packet_data
    BDFD-2              1 a
    R2D2-22             3 aa
    BDFD-2              1 b
    R2D2-22             3 bb
    EMC2-0              2 aaa
    EMC2-0              2 bbb
    

    And the code …

    Public Sub RenumberPacketIDs()
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim lngPacketID As Long
        Dim strLastPacketID As String
        Dim strSql As String
    
        strSql = "SELECT PacketID, new_PacketID" & vbCrLf & _
            "FROM tblPackets" & vbCrLf & _
            "ORDER BY PacketID;"
        Set db = CurrentDb
        Set rs = db.OpenRecordset(strSql)
    
        With rs
            Do While Not .EOF
                If !PacketID <> strLastPacketID Then
                    lngPacketID = lngPacketID + 1
                    strLastPacketID = !PacketID
                End If
                .Edit
                !new_PacketID = lngPacketID
                .Update
                .MoveNext
            Loop
            .Close
        End With
    
        Set rs = Nothing
        Set db = Nothing
    End Sub
    

    I think an approach like that could be fine for a one-time conversion. However if this is an operation you need to perform repeatedly, it could be more complicated … especially if you need each PacketID replaced with the same number from one run to the next … eg. BDFD-2 was replaced by 1 the first time, so must be replaced by 1 every time you run the procedure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for a long question and not a very descriptive title, but my problem
Firstly, sorry about the question title, it may not be very descriptive for my
Sorry about the title. I do realize it's not very descriptive. :| Here is
Sorry for the not very descriptive question title. I'm not very sure how to
I am sorry for possible misleading about the title, but I have no idea
Sorry if title is not too clear but I think it's about right. NEhow,
Sorry about the title but could not come up with anything really informative and
sorry if the title is very confusing, but I'm not sure how to really
Sorry the title isn't more specific. I have some minor problems with a jquery
Sorry if the title is not very clear. I was not sure about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.