Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    Quote Originally Posted by Micron View Post
    AFAIK, you cannot rs!variableNameHere because of how the bang operator works. You'd have to use rs.fields(variableNameHere)? However, what's the point of assigning the field name to a variable when you know the field name? Might as well just use rs!Field1 if that is the field name.
    IIRC, someone suggested that "fields" is not required with that syntax but I've always invoked it and won't ever change. That's how shortcuts and sloppy code can stop working after Access updates.
    I think O/P just copied @June7's code from post 3 without fully amending for their situation.?
    All they changed was the table name?
    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
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,426
    Right, and I'm guilty of mixing up strF1 with Field1New
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Did you add Field1New and Field2New fields to the table?

    I tested code and worked.
    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. #19
    DBS1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    47
    Quote Originally Posted by June7 View Post
    Did you add Field1New and Field2New fields to the table?

    I tested code and worked.
    June7 - I just added the two fields to the table and it worked. I misunderstood your original suggestion, thinking the code would add them...my bad. I can live with this, but the source is a txt file, and gets updated periodically, so I would need to re-import when revisions are done and would have to add the two fields each time. That is not a problem, but if there's a way to build a query and do something similar with the code, then that might be better. If not, I am content with what you've shown me here. Either way thanks to you and all of the others for your time and patience.

  5. #20
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    You do not add two fields each time, you add them once (which you have already done), and be done with it. Then you just update them.
    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. #21
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Aren't you importing to existing table? If not, why not?
    If using existing table, probably should modify procedure to only pull new records in recordset. How to do that? Add another field such as ImportDate and also populate it in the update. Then recordset only pulls records where ImportDate IS NULL.
    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
    DBS1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    47
    Quote Originally Posted by CJ_London View Post
    Not sure we can trust the sql you have posted, or the source you are displaying is not the source you are referencing in the query -Hurdat2_1Field1 should be Hurdat2_1.Field1 otherwise will generate an error, Hurdat2_1.field2 would have appeared as Hurdat2_1.Field2 - and all those 'AS Expr' implies you have not used the query builder - or if you have they are somehow calculated


    And given we are now seeing a more realistic set of data, you need to remove

    AND ((Hurdat2.field3) Is Not Null)

    from the criteria since you have values in that field for ID=6 for example.

    More importantly, that means that field3 is text, not numeric so the bit of the criteria you removed needs to be replaced with

    (Hurdat2_1.ID)<=[Hurdat2].[ID]+val([Hurdat2].[Field3]))

    That is probably the reason you had a problem with the other method as well.

    shame you didn't include row 6 in your original example data, wasted a lot of time

    CJ London - first I apologize for the lack of data and appreciate that you took the time to help me. June7's post gets me what I need, but I'd also like to see if I can get what you've suggested to work. I've tried to follow along with your suggestions but it is still not working, and I'm getting a "Data type mismatch in criteria expression", perhaps because the fields are text fields? Here is the latest code based on your post #6. If you see where the problem might be, please let me know.

    SELECT Hurdat2.Field1, Hurdat2.Field2, Hurdat2_1.ID, Hurdat2_1.Field1, Hurdat2_1.Field2
    FROM Hurdat2 INNER JOIN Hurdat2 AS Hurdat2_1 ON Hurdat2_1.ID>[Hurdat2].[ID] AND Hurdat2_1.ID<=[Hurdat2].[ID]+val([Hurdat2].[Field3]);

  8. #23
    DBS1 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    47
    Quote Originally Posted by June7 View Post
    Aren't you importing to existing table? If not, why not?
    If using existing table, probably should modify procedure to only pull new records in recordset. How to do that? Add another field such as ImportDate and also populate it in the update. Then recordset only pulls records where ImportDate IS NULL.
    Thanks June7 and Welshgasman. I haven't had the need to import updated data yet, as I'm just now building this, so that's really helpful to know. I think you guys have solved this for me. Can't thank you guys enough, including all of the others who responded in the other posts.

  9. #24
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    you've moved to the other suggestion I made

    suggest provide some example data - perhaps 100 rows

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

Similar Threads

  1. Transposing data in a report
    By Rudolf14 in forum Access
    Replies: 5
    Last Post: 09-06-2019, 06:09 AM
  2. Transposing columnar data to row data; Export to excel for SPSS
    By jondavidf in forum Import/Export Data
    Replies: 6
    Last Post: 01-25-2019, 06:42 PM
  3. Transposing Linked Data
    By Rustin788 in forum Access
    Replies: 4
    Last Post: 03-09-2017, 03:46 PM
  4. Transposing row to column in Access 2010
    By nshatz in forum Access
    Replies: 2
    Last Post: 06-02-2015, 10:38 AM
  5. Transposing Data
    By NoiCe in forum Queries
    Replies: 0
    Last Post: 11-09-2008, 05:24 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