Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Why is just the table Security table causing the error the other two tables, mtShrs and mtSelectedRates, accepted?
    I do not know any other way of saying this.



    I believe it is not SECURITY.Invested but Security![Invested] that is the issue.
    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

  2. #17
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Me too. Please see the last line of code in post #12.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #18
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    Either way, it is likely the query is not updateable given the 3 tables involved.

    It really isn't clear to me what the OP is trying to achieve.

    Do they want to open a recordset which they can then edit using VBA?

    Or do they want to create a new table and then open the new table to edit it in VBA?

    Or something else?

  4. #19
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    And we need sample data. Can build (Advanced posted editor) or copy/paste tables into post or attach file (again, Advanced post editor).

    Just looked at the original SQL again. Linking two primary keys to the same foreign key makes no sense, especially if those primary keys are autonumber.
    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.

  5. #20
    Ed Bitzer is offline Novice
    Windows 10 Office 365
    Join Date
    May 2025
    Posts
    17
    June7 I am not helping you or the others help me. I had corrected to MySet = MbDb.OpenRecordset(strSql) which I thought was for non-action queries. However you indicate I use "Set". Appreciate if you would give me syntax.

    Sorry about not responding to duplicating which I am not doing. I move through the records modifying the myset.pays field depending on the Myset![SecType] to either MySet![Rate] * 0.01 * Security.Invested * MySet![Shrs] or MySet!Pays = MySet![Rate] * 0.01 * MySet![FaceValue] * MySet![Shrs]. But I have to get past the error that External Name is not defined for Security"

    Ed

  6. #21
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Your original code used SET which is correct for opening a DAO recordset. The SQL statement was not valid.

    As already explained by others, line should be:

    MySet![Pays] = MySet![Invested]

    Which appears to be simply duplicating Invested into Pays.

    Nothing you provided shows any calculations are taking place nor any conditional decision.

    However, cannot populate a recordset field without first putting recordset into edit mode.

    Example of code for opening, looping, editing DAO recordset:

    Code:
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("some valid SELECT query")
    Do While Not rs.EOF
        rs.Edit
        rs!somefield = somevalue
        rs.Update
        rs.MoveNext
    Loop
    Alternative to looping a recordset would be UPDATE sql:
    CurrentDb.Execute "UPDATE tableORquery SET somefield = something"

    Saving calculated data is usually not advisable, calculate the value when needed.

    If you need more assistance, suggest providing db for analysis.

    Without clarification of data structure and business process this procedure should support, I may have to back away.
    Last edited by June7; 08-05-2025 at 04:24 PM.
    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.

  7. #22
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    I’m dropping out anyway as the OP is not clear about what they are trying to do, only the way they think it should be done

  8. #23
    Ed Bitzer is offline Novice
    Windows 10 Office 365
    Join Date
    May 2025
    Posts
    17
    I am discouraged that I have not made clear by objective as noted by London and June7. Apparently the code examples I gave to not make clear that I am trying to update the Pays field in field for two types of investment, "S"tocks and "B"onds. To this end I must cycle through the records and make the proper calculation based on I am doing this by cycling thru the fields displayed in the query and modifying Rate based on records from the other three tables. June 7 clearly points out that omision which is in a couple dozen lines of code before the Update and Next ctr (actually the months).
    Be patient, have to hit the hay now (remember I am 92) and I will try again to answer every one of June7 questions in response #8, which I obviously did poorly in #20. I suspect I should offer the complete code (and I have found the # symbol on the main menu of Quick Reply). If I do not do that clearly I believe I will have to modify the code to create a make table and then walk through that table in a way I am more familiar.

    Ed

  9. #24
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Could you just use an update query and a UDF to calculate the new 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

  10. #25
    Ed Bitzer is offline Novice
    Windows 10 Office 365
    Join Date
    May 2025
    Posts
    17
    I now find you have given me all the answers but accompanying far to much other information and questions for this old mind to handle. A lot of that extra stuff was becuase my original question not clear and including a mistaken quote (I was testing the alternative approach of creating a temporary table rather than work directly with a recordset created on the fly from SQL. I actually was using a select query, I was testing this update query which when properly opened still created an error with the reference to the Security tabe.

    I problem from the start was that I created a recordset and then incorrectly referred to to the Security table. It should have been MySet![Pays] = MySet![Invested] as noted by June7 in in reply #21 - me bad. By the way that line of code may not make much sense but was included just to create the error early in a sub that is several pages that include necessary references later.

    All is well that ends well.

    Ed

  11. #26
    Ed Bitzer is offline Novice
    Windows 10 Office 365
    Join Date
    May 2025
    Posts
    17
    I do not know how to mark this thread as solved. No option under Mark Tools.

    Ed

  12. #27
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Quote Originally Posted by Ed Bitzer View Post
    I do not know how to mark this thread as solved. No option under Mark Tools.

    Ed
    Thread tools, top right on green thread toolbar.
    There is even a button on the very top toolbar that shows you how?
    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

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

Similar Threads

  1. Report Indicates Multiple Pages
    By stevebp in forum Reports
    Replies: 5
    Last Post: 03-18-2020, 03:56 PM
  2. Replies: 7
    Last Post: 01-10-2020, 04:50 PM
  3. Replies: 1
    Last Post: 12-14-2012, 12:32 AM
  4. Replies: 4
    Last Post: 06-08-2012, 09:08 AM
  5. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 PM

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