Results 1 to 10 of 10
  1. #1
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18

    update without addnew or edit in VBA code

    How do I resolve the error update without addnew or edit?
    I need to stay with VBA. All the files are flat with a few columns.
    What rule am I missing?

    [code Sub Updater()
    Dim SortedAllnamesx2 As Recordset
    Set SortedAllnamesx2 = CurrentDb.OpenRecordset("Sortedallnamesx2")
    Dim Allnames As Recordset
    Set Allnames = CurrentDb.OpenRecordset("allnames")
    Dim Deletable As String
    SortedAllnamesx2.AddNew
    SortedAllnamesx2![aname] = Allnames![aname] ' object required
    SortedAllnamesx2![lot] = Allnames![lot]
    SortedAllnamesx2![location] = Allnames![location]
    SortedAllnamesx2.Update


    'Allnames![aname] = Deletable
    Deletable = Allnames![aname]
    Allnames.MoveFirst
    Do While Allnames![aname] <> Deletable
    Allnames.MoveNext
    Loop
    Allnames.Delete
    Allnames.Update ' ERROR msg "update without addnew or edit"
    Allnames.MoveFirst
    [/code

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    You don't have to ".Update" a .Delete

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Why are you duplicating records to another table?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    "All files are flat with a few columns"

    If all you want to do is move records from one table to another, why not call a (parameterized) append query and then a (parameterized) delete query? If you want to move just a subset of the entire table for some reason, just make sure the filters for the two queries are the same. Doing it with a recordset is, I think, the very least efficient way of doing it.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Think about it, what are you going to update, if you have just deleted the record?

    Error message means what it says.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18
    I want to stick with VBA coding. Over all problem is I have a form to print a list from allnames, sorted on load by name.
    The family wants a printed copy, which takes a lot of paper, 800 names. I want to put 2 columns on a page, with the
    2nd column being the lower half of the first column.

  7. #7
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18
    I want to stick with VBA coding, yes I am old school. Over all problem is I have a form to print a list from allnames, sorted on load by name.
    The family wants a printed copy, which takes a lot of paper, 800 names. I want to put 2 columns on a page, with the
    2nd column being the lower half of the first column.

  8. #8
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18
    I want to stick with VBA coding. Over all problem is I have a form to print a list from allnames, sorted on load by name.
    The family wants a printed copy, which takes a lot of paper, 800 names. I want to put 2 columns on a page, with the
    2nd column being the lower half of the first column.
    Can I have 2 tables supporting the same form? One for column 1 and one for column 2?

  9. #9
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18
    I want to stick with VBA coding, yes I am old school. Over all problem is I have a form to print a list from allnames, sorted on load by name.
    The family wants a printed copy, which takes a lot of paper, 800 names. I want to put 2 columns on a page, with the
    2nd column being the lower half of the first column.
    Can I have 2 tables supporting 1 form?

  10. #10
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    I'm lost. Why not use a report to print?

    Are you doing this backwards deliberately? VBA is fine. I have nothing against it, but there are many easier ways of accomplishing things. Use VBA when you need to do something perhaps out of the ordinary. Create a two-column report. Then set the sort order in your report.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 08-26-2020, 06:54 AM
  2. Update or CancelUpdate without AddNew or Edit -- 2019
    By bw.brandiwoodson in forum Forms
    Replies: 10
    Last Post: 12-06-2019, 01:44 PM
  3. Update or CancelUpdate without AddNew or Edit
    By westcoastbmx in forum Forms
    Replies: 5
    Last Post: 11-07-2019, 09:01 PM
  4. Replies: 1
    Last Post: 07-18-2015, 07:59 PM
  5. Replies: 3
    Last Post: 03-07-2011, 08:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums