Results 1 to 6 of 6

Thread: [RESOLVED] Another Access VBA RS Question

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] Another Access VBA RS Question

    I am getting an invalid operation error on the underlined section of code. I cant understand it im copying straight from a book for this stuff and the book always seems to be wrong.
    VB Code:
    1. rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic, adCmdText
    2. StatetoAdd = Me.lstStateList.ListIndex
    3. With rs
    4. [U].AddNew[/U]!FK_State = StatetoAdd
    5. .Update
    6. .Close
    7. Populate_lstEmpStates
    8. End With

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Another Access VBA RS Question


    VB Code:
    1. rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic, adCmdText
    2. StatetoAdd = Me.lstStateList.ListIndex
    3. With rs
    4.     .AddNew
    5.     .Fields("FK_State").Value = StatetoAdd
    6.     .Update
    7.     .Close
    8.     Populate_lstEmpStates
    9. End With
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Another Access VBA RS Question

    I still get the error Invalid operation on the .AddNew Line
    VB Code:
    1. rs.Open strSQL, cnn, adOpenDynamic, adLockOptimistic, adCmdText
    2. StatetoAdd = Me.lstStateList.ListIndex
    3. With rs
    4.     .AddNew
    5.     .Fields("FK_State").Value = StatetoAdd
    6.     .Update
    7.     .Close
    8.     Populate_lstEmpStates
    9. End With

  4. #4

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Another Access VBA RS Question

    I have changes the underlying record sets SQL to a more simlple - select star from employee states which clears the above error but sticks on the .update line with ODBC call failed. any ideas..

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Another Access VBA RS Question

    Are there other fields in the table which need to be set? (ie: do not allow Null)

    If so, you'll need to add more lines like .Fields("FK_State").Value = StatetoAdd

  6. #6

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Another Access VBA RS Question

    Yes Si that was the problem... Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width