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

  • Home
  • SEARCH
  • 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 252519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:41:05+00:00 2026-05-11T21:41:05+00:00

I have this code that I am trying to copy a record with in

  • 0

I have this code that I am trying to copy a record with in VBA. Unfortunately I cannot get it to work. I do not knw why it won’t do anything.

Dim OldRecord As DAO.Recordsets, NewRecord As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT [Tote Log].* FROM [Tote Log] WHERE Number = " & _
            Me.tbScannerRead.Value

Set OldRecord = CurrentDb.OpenRecordset(strSQL)

If OldRecord.Count = 1 Then
    Set NewRecord = _
                CurrentDb.OpenRecordset("SELECT [Tote Log].* FROM [Tote Log]")
    With NewRecord
        .AddNew
        For i = 0 To .Fields.Count - 1
            .Fields(i).Value = OldRecord.Fields(i).Value
        Next i
        .Fields("Number").Value = Me.tbScannerRead & "B2"
        .Update
        varBookMark = .Bookmark
    End With
    NewRecord = varBookMark
    DoCmd.RunCommand acCmdSelectRecord
    Me.tbMessageBox = "Added new record"
    Me.tbMessageBox.Visible = True
    GoodToteRead = False
    Me.tbScannerRead.SetFocus
End If

I get nothing, I am trying to copying a record from the tote log and change the number from, lets say, L20444 to L20444B2 and have the same field information as the original. This is where I am so far but I get nothing. Ahy Help would be greatly, and I mean greatly, appreciated. Thanks

  • 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-11T21:41:05+00:00Added an answer on May 11, 2026 at 9:41 pm

    There are a few things that could be causing it. Here is one. Does your table have a primary key? It looks like you are trying to update the primary key to a value that already exists in the table before changing it. Is this happening on a form? If so Access can get upset at you for changing a recordset behind it’s back. a me.undo() before making changes can help. Also if you are on a form you can acomplish the same thing this way. It’s a bit hacky, but it is the easy way.

    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.GoToRecord , , acNewRec
    DoCmd.RunCommand acCmdPaste
    

    As an alternative, I would recommend something along these lines.

    Dim sSql As String
    Dim sUpdateSuffix as string
    sUpdateSuffix="B2"
    Const sTableName As String = "[Tote Log] "
    sSql = "INSERT INTO "[Tote Log]([number],[whateverelse]) " & _
           "SELECT [number]" & sUpdateSuffix & ",[whateverelse]  FROM [Tote Log] WHERE Number = " & Me.tbScannerRead.Value
    CurrentProject.Connection.Execute sSql
    

    If you want to build the sql string dynamically use the same method as you already used to loop through the fields and build the query string.
    me.requery will rebuild the form recordset.

    Hope that helps you

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

Sidebar

Ask A Question

Stats

  • Questions 180k
  • Answers 180k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are constantly overriding $_SESSION['pages']. Create an array and add… May 12, 2026 at 4:07 pm
  • Editorial Team
    Editorial Team added an answer Write up a delegating Set that wraps the real Set… May 12, 2026 at 4:07 pm
  • Editorial Team
    Editorial Team added an answer You don't actually need a new extension method - there's… May 12, 2026 at 4:07 pm

Related Questions

I have an XML that I need remove empty elements from. I am trying
I have recently discovered that when I have pointers within a class, I need
I have a class, A , in C++/CLI which derives from a templated base
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.