Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32
  1. #16
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Vlad



    Changed the Code to the following but now get the attached error.


    Code:
    Private Sub cmdUpdate_Click()
    
    10        On Error GoTo cmdUpdate_Click_Error
          Dim strSQL As String
    20    If Me.Dirty Then Me.Dirty = False
          Dim rs As DAO.Recordset 'Object
    30    Set rs = Forms!frmPurchaseDates!frmPurchasedItemssubform.Form.RecordsetClone 'Vlad assumes the subform control has the same name as its source object; your original expression would work as the form is not actually open as a stand alone form
    40    With rs
    50    Do While Not .EOF
          'Do Something
    60      strSQL = "UPDATE [tblStock] SET InvQtyOH = " & Nz(rs("Qty"), 0) + Nz(rs("InvQtyOH"), 0) & " WHERE StockID = " & rs("StockID") & ";"
    70    Debug.Print strSQL
    80      CurrentDb.Execute strSQL, dbFailOnError
    90    .MoveNext
    100   Loop
    110   End With
    120   rs.Close
    130   Set rs = Nothing
    140   MsgBox "All Stock Updated", vbInformation
    
    
    150       On Error GoTo 0
    160       Exit Sub
    
    
    cmdUpdate_Click_Error:
    
    
    170       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdUpdate_Click, line " & Erl & "."
    
    
    End Sub
    Attached Thumbnails Attached Thumbnails error.png  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  2. #17
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Vlad
    I have attached a stripped down version so that you can see what I am attempting to do.

    Any help appreciated
    Attached Files Attached Files
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Why are you surrounding the fields with brackets?
    Have you even looked as to how you reference recordset fields?
    There are several ways. You appear to be trying to.mix two of the methods?

    https://www.access-programmers.co.uk...ariable.89838/
    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

  4. #19
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Welshgasman

    Are you referring to [tblStock] ??
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  5. #20
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Here you are Mike, you needed a dLookup as the InvQtyOH was in another table, hence the error.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #21
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by mike60smart View Post
    Hi Welshgasman

    Are you referring to [tblStock] ??
    No, your quantity fields in the recordset.
    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

  7. #22
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Vlad

    You are a star as always.

    There is no way I would have been able to achieve this without the help of the forum.

    Many thanks again
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  8. #23
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I owe you an apology Mike.

    I have seen formats of

    Code:
    rs.Fields("Qty") and
    rs!Qty
    but never rs("Qty"), which is why I thought you were mixing the two, knowing your lack of VBA.

    Seems that also works as well?

    So apologies for that at least. The reminder of recordsetclones and form controls still stands however.
    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

  9. #24
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Not really Mike, I might just have a bit more experience with this stuff ��, glad to hear it works now.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #25
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    but never rs("Qty")
    Don't know where I read a comment on that recently but it was news to me when I came across it. Apparently it is like .Value in that Value is seldom required because it is the default member of many controls/references. IIRC Fields is the default for recordsets so rs("myField") is the same as rs.Fields("myField"). While I don't usually use .Value, I would probably use .Fields because it seems to be not as well known.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #26
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Micron View Post
    Don't know where I read a comment on that recently but it was news to me when I came across it. Apparently it is like .Value in that Value is seldom required because it is the default member of many controls/references. IIRC Fields is the default for recordsets so rs("myField") is the same as rs.Fields("myField"). While I don't usually use .Value, I would probably use .Fields because it seems to be not as well known.
    When I started with Access I searched on how to reference fields in the recordset, the .Fields() syntax was the first I came upon, and so I used that.
    Then I discovered the bang syntax, which is at least less to type?
    Now I have a third, though that is still more to type than the bang syntax, if only by one character.

    If you use Tempvars, you have to use the value for the field/control, otherwise Access thinks you are trying to assign an object, which a Tempvar cannot hold.
    Catches me out most times, having got used to NOT using .Value.
    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

  12. #27
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I know I'm late to the party here, but unless I'm missing something this could be much more easily done with a simple update query?

    No need for any recordset machinations, which we all know Mike struggles with?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  13. #28
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Minty
    I did try an Update query but with no luck

    How would you structure the query?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  14. #29
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    And I thought I had a bad memory?

    https://www.utteraccess.com/topics/2065471?post=unread
    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

  15. #30
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Welshgasman
    I knew I had used this previously but could not find the file I had saved with the code.

    Many thanks and maybe I will remember now.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Recordset refuses to update :)
    By ironfelix717 in forum Programming
    Replies: 7
    Last Post: 03-09-2020, 12:32 PM
  2. Recordset to update a table
    By john134 in forum Programming
    Replies: 6
    Last Post: 04-19-2017, 11:01 AM
  3. recordset won't update
    By charlieb in forum Access
    Replies: 3
    Last Post: 04-13-2015, 05:56 PM
  4. Update recordset - 'Not responding'
    By tariq1 in forum Programming
    Replies: 2
    Last Post: 08-11-2012, 11:33 AM
  5. Update Query?? or RecordSet??
    By bbrazeau in forum Queries
    Replies: 2
    Last Post: 01-13-2012, 08:44 AM

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