Solved In form, move to another record with known ID

Regarding the video: As if I had trouble in knowing how to create a partially duplicated record... No big thing at all using VBA. But with a properly normalized structure, there is usually nothing to copy except a PK/FK situation.

I realized that even I as the OP might have a problem understanding all the posts here.

I would hope so, as otherwise the implication would be that you have been asking questions to which you already knew the answer and just wanted to waste our time.

As to my original response, I may have been focusing on the Macro solution and for that, my answer was quite correct. Using a CopyRecord macro, you have to EITHER pre-edit or post-edit the record before selecting and copying it and pasting it, because otherwise it is a whole-record operation and you get key violations. With a pre- or post-edit of the record, it becomes my case (c) - regardless of using a raw copy or a macro or some VBA to edit selected fields behind the scenes.

What fool would think if they are on record 2 and want to copy record 1 that the system would magically divine that?

If you've been here long enough, you wouldn't have to ask that question. You would have seen for yourself.
 
@twgonder
Can you mock up a simple database, a people table and a form where you use arnelgp's method and it doesn't work and post it here?
Because his code works here, no matter how many times I test.
 
@ KitaYama Here you go. This is what I showed in post #33
Several developers in various articles, and some here, have said not to use autonumbers as a reference.
I get it as I watched this short video some months ago:
Microsoft Access AutoNumbers Are NOT For You (599cd.com)
So, I modified arnelgp's test .accdb with one field to incorporate this simple idea.
Cheers!
 

Attachments

Last edited:
[Person Code] is set to NoDuplicate in your table design.
If you want to copy and save the new record, you have to change [Edit Person] prior to running with .RunCommand acCmdSaveRecord.
Because your Person Code can not be a duplicated text.

Or change the field property to accept duplicates.


No offense but we are on post 50 and it is a design problem. Yet you blame Access.

PS: And as a professional programmer you should know better not to use space in your field name.
 
Last edited:
[Person Code] is set to NoDuplicate in your table design.
If you want to copy and save the new record, you have to change [Edit Person] prior to running with .RunCommand acCmdSaveRecord.
Because your Person Code can not be a duplicated text.

Or change the field property to accept duplicates.


No offense but we are on post 50 and it is a design problem. Yet you blame Access.

PS: And as a professional programmer you should know better not to use space in your field name.
As to the field space name, (I know, I know) that may have been an inadvertent error (I copied stuff quickly--it was an example and not a production db, so I didn't give a lot of attention to proofing stuff--the point was the error in copying). Check the next post for a cleaned up version that tackles your other issues.
 
Last edited:
Okay, for those that stuck it out this far, this should help you see what I was looking for...
AND THE SOLUTION!
(Yes, I know, I know, it's not the only or ultimate solution, it's just mine for now.)

I tried to keep it simple. I used the original .accdb from post #17 and modified it to my standards.
Now, you may not like all the code, I'm still working on that and cleaning it up. The core of my experience is not in Access.
I cut this code out of my bigger helper form module (mod_Form), so there's a lot you aren't seeing.
There's also a lot of code and variables missing, for things like the user, that I fudged, to keep it simple.
I'm working on a template, and the helper form procedures are meant to be written once and used by all forms based on the template.
You may not like that idea, but if you do you can see how to implement it.

Code was also pasted out of other modules, so they wouldn't normally be in the form helper module. Again, to keep it simple.
There's some kernel stuff normally there, like the pause that I didn't add so no one can claim I crashed their system.
If you try to copy more than one record a second you will get an error, the error will result in a stop.
I use stop in development to catch errors and fix them, if you don't know how to use VBA don't create more than one copy a second!
As to this error, using now() is just a stop-gap measure until I get my sequential Id/Code routines written (another thread).

I tested the form based on the needs of the original post, and it worked in my Access 2021. Your version may behave differently, and you may crash the form if you try to do stuff outside the scope of this thread, I'm not going to test it for all possibilities, because it's not meant to be a fully functioning form for production.

My thanks to all those that were constructive in the development of this solution. Enjoy!
 

Attachments

Last edited:
I'm still working on that and cleaning it up
there's a lot you aren't seeing.
There's also a lot of code and variables missing,
Code was also pasted out of other modules, so they wouldn't normally be in the form helper module
There's some kernel stuff normally there, like the pause that I didn't add so no one can claim I crashed their system.
If you try to copy more than one record a second you will get an error, the error will result in a stop.
you may crash the form if you try to do stuff outside the scope of this thread,
I'm not going to test it for all possibilities, because it's not meant to be a fully functioning form for production.
I really can't understand what's the point of posting a database with above situation.


And personally this section is my favorite:
if you don't know how to use VBA don't create more than one copy a second!
 
Last edited:
I really can't understand what's the point of posting a database with above situation.
And personally[sic] this section is my favorite:
Well, it's not a database for anyone to use in production (as is customary in a Forum like this one).
It's a demo database that shows how one can copy a record,
and then most importantly based on my original post, how to move to that record.
Did it do that for you?
Now if you pick up any pointers (that I copied and modified from others in some cases) then great, no harm done.
As to the VBA warning, it's just that, a warning that came with an explanation (which you conveniently omitted).
If you can get that all done in three or four lines of code that are generalized and parameterized (not hard-coded), I'm all eyes.
 
Last edited:
and then most importantly based on my original post, how to move to that record.
Did it do that for you?
No it didnt. I think it has something to do with the value of temp1 as .findfirst jumps all over the place. I'm assuming you want findfirst to go to the newly added record.
Then again I find your coding style impossible to understand.
 
No actual expert would ever suggest creating a macro.
I agree, I think macros are obscure and not very flexible. But then, you have to ask, why did the "experts" that created Access create so many different macro actions? Why does M$ keep calling VBA code "macros" in the documentation? Very confusing for a RAD or any other db tool.

If you were referring to Richard's videos, He has several levels of instruction, and in most of his videos he is very clear that this is a macro, but he'll show the better way in VBA for his members. "You have to learn to walk before you can run", he often repeats in the videos.

My experience in dbs on MF/SM was quite different from the way Access works. Everything started at the record level and all the programming language commands in BASIC were geared towards that. You could, as an option, feed the programs a "list" of selected records based on the equivalent of a SQL with where, but then you had control on a record-by-record, field-by-field basis. So, things like the copy and move in this example thread were a trivial task. In a post on this thread (Solved - Sequential numbers | Page 4 | Access World Forums (access-programmers.co.uk) I shared a little snip of code that reads and writes sequential numbers very effeciently, no big SQL or DAO routines needed, just a simple read and write. It's too bad M$ didn't think to add something simple like that in Access, other than the DLookup function (I don't think there is an equivalent write function).

I expect that at the local level (i.e. a store or government office) the ACE BE should be able to handle less than twenty concurrent users without a problem. Two years ago I took my old db application and scaled the automated test to 100 users pounding tens of thousands of records each, and it didn't blink on a slower laptop, so Access ACE shouldn't be too bothered. This all thanks to how fast hardware is these days and with all that memory available.

Oh, oh, oh I'm curious if anyone has tried an Access BE on Amber (product on Amazon) just for fun? That should be a new thread I suppose.
 
No it didnt. I think it has something to do with the value of temp1 as .findfirst jumps all over the place. I'm assuming you want findfirst to go to the newly added record.
Then again I find your coding style impossible to understand.
Odd, I've tested it about 50 times, and it hasn't failed me yet. It's supposed to jump to the new record that was copied. Did it go to some other record than the new one for you? A good way to tell is look at the minutes and seconds in the EntityCd text box (you may want to make that one character wider for the full seconds, or change the font size.). The name fields should remain the same. If it's not the current time, the form code went to the wrong record.

There's bits of code that are mine, and lots of modified from others, so I'm not sure which you're having trouble understanding. Doing an F8 through the code should provide some insight. Thanks for helping with the testing on other versions/computers.
 
Last edited:
It only jumped to the new record once. All other attempts it went to record 4 of 7, 7 of 15, etc. F8 is no help as it seems to be endless going thru loops like crazy.

I'm not sure which you're having trouble understanding
Pretty much all of it. I'm pretty active on several forums and most code I can follow. Yours not so much.
 
Why does M$ keep calling VBA code "macros" in the documentation?
That will be office documentation
But then, you have to ask, why did the "experts" that created Access create so many different macro actions?
for those who have simple requirements and don't want to learn VBA

Oh, oh, oh I'm curious if anyone has tried an Access BE on Amber (product on Amazon) just for fun? That should be a new thread I suppose.
never heard of it, but definitely for a new thread. Not clear whether this is a service like onedrive/google drive or a net based rdbms. If the former, then no it won't work and if the latter an access FE should be able to connect to it providing it is ODBC compliant. Wouldn't have thought it was of interest to you since your objective is to avoid anything that relies on the internet.
 
It only jumped to the new record once. All other attempts it went to record 4 of 7, 7 of 15, etc. F8 is no help as it seems to be endless going thru loops like crazy.


Pretty much all of it. I'm pretty active on several forums and most code I can follow. Yours not so much.
Okay, I understand, a lot of times I don't understand other's code either. That's the way it is.
Are you saying you're getting caught in a real endless loop? In that case the form will stop working, I haven't seen that.
Yes, string array manipulations are all about loops, you can easily set a break-point for after their execution to avoid the loops.
Count, find, extract, replace, insert, delete are common enough string commands, just not in Access. So, I had to write the subs and functions. Maybe that's what's confusing to you? I'm pretty sure I added enough comments to explain what they're doing. They're not so important to the original post and purpose of copy. They're used to manipulate the record before write.
As to the record 4 of 7, etc. I presume you understand how random ANPKs work. That's Access, not my code.
Did you find a wrong name or wrong time after a copy?

Everything in my table exactly as it should be:

220923Copy4.jpg
 
Last edited:
never heard of it, but definitely for a new thread. Not clear whether this is a service like onedrive/google drive or a net based rdbms. If the former, then no it won't work and if the latter an access FE should be able to connect to it providing it is ODBC compliant. Wouldn't have thought it was of interest to you since your objective is to avoid anything that relies on the internet.
Amazon.com: AMBER X Smart Personal/Home Cloud Storage Device for Data and Media Files, Built-in 512GB High-Speed SSD with USB Storage Expansion, iOS/Android/Windows/Mac Compatible, Black : Electronics

They just aren't real clear as to whether it runs Windows Apps or not.
 
Last edited:
It doesn't when you look at Access documentation.

In Excel, VBA is called macros.
I've seen it many times over the years. I'll keep an eye out and post back next time I see such a macro reference for VBA in M$ documentation.
(I'll just have to remember which thread this is.) 😆
 
Are you saying you're getting caught in a real endless loop?
No, I set the break in the beginning of the code and had to hit F8 for 10 minutes.
Yes, string array manipulations are all about loops, you can easily set a break-point for after their execution to avoid the loops.
Ya should have probably said that first.
 
Not sure why you are using Option Compare Binary. All the rest can be read in post #66

Thanks for your thoughtful comments. Yep, I'm working in Spanish, French, Portuguese, Italian and English, so far with the app.
What part of moke123's response do you agree with? I think I addressed all his concerns in post #63.

I'll read your articles on compare to see how it applies. I just know I was getting "c" equal to "C" in my code, and from my historical experience, that too can cause problems. I'm not sure my subs would affect how Access perfoms SQL commands. I'll check it out.
Some of what you say is subjective, take the Dims for example. You can have 50 lines of dims or 10 rows with multiples in a complex program, I'm not one for scrolling through pages of Dims. But to each their own.

My generic procedure works for any form I hope to build, as it does in the demo I posted, so I'm not sure what your objection is.
BTW, that's not "my" routine for copying (since there aren't obvious line numbers in Access, it's hard for me to know exactly which part of any procedure you have a concern about-only with that can I say who the author was). As I've stated several times in posts, I started with the copy code from an Access 20+ year instructor and developer. I had to read the code line by line and lookup most of the commands, as they are foreign to me and my experience designing at the OS level, developing RAD tools and large applications in languages ranging from assembler to higher level languages like BASIC. VBA is its own unique animal, as were the systems I worked in before.

I'm not sure what to say about your observations on arrays. There's nothing that says arrays have to be "same data types". Even Access itself isn't designed that way or why allow arrays as variant? XML was designed around the concept opposite of structured data and nobody seems to complain that is "bad". It would be silly to say that Access itself should only allow one type of field in a table. I don't see any advantage to using TempVars over a normal array in this situation. In fact, it doesn't allow for variant and that opens up the null can of worms to any sub/function I use that can properly have a null.

I've designed hundreds of forms over the years. I even included a snip of code similar to a form class module in the sequential number thread I recently posted. It was from the RAD tool I had built some 30 years ago and is still in commercial use today. I also added some RAD record parameter code in a post to DOC that clearly shows the use of forms in the application (although they are called screens, not forms). So, I'm not sure where you got the impression my experience is only in "batch", whatever that is since it has many meanings in computing.

I'm perfectly capable of hardcoding non-generic code, as my first commercial assembly job was writing code into firmware. I like making high level code more flexible than that. If that wasn't the case in Access, then there wouldn't be the intense focus on everything being a function or sub, or the ability to make calls. That's the whole point of higher-level languages; to be more generic and cross functional. However, you are welcome to write all your form class modules to be very specific to just that one form, and do it over-and-over again for the same basic logic, and then maintain all those versions when a bug is found or enhancement is needed. I've seen it before, and that's your choice, not mine thank you.

BTW, when I was first playing with how I wanted the template to work, I did hardcode specific mods to the record, and then I thought, how can I make this work for any form? And then wrote the code you now see. I've been through the same cycle about a dozen times while working on the template. That's the whole point of a template, to be generic that can then be customized to a particular task.

I'm confused about the problem with the new record being dirty comment. In the test I just did with a modified TWG.accdb, it doesn't go dirty until a textbox is changed. I've tweaked it a bit more for very minor appearance changes, so I doubt it would make a difference to what you claim. But if you have a dirty record, and can show it after the copy with a snip, I'll go download my twg.accdb and check. P.S. Okay, I went and downloaded my posted TWG.accdb, and it's not dirty on the newly created record and it can be modified as needed as a copied record. I would like to know on what version of Access you see a different result. The whole idea is to copy the record, go to the new one, and make user changes there, in the new record. Certain changes have to be made for the copy record before it's actually copied to avoid conflicts with the table properties, like no duplicates in an indexed field.

I'm not sure what you mean that my code doesn't run in the before update procedure. You can clearly see on the form that the update stamp changes to a new date when saved, so it had to run to do that. Can you tell me exactly where it doesn't work for you? In my testing it works fine.

Again, I was pretty clear in the original post what I wanted. It's not what everyone wanted to talk about though. Here's the actual question, "How can I "move" to that new record in the same open form with VBA ?" Notice that the question doesn't include how to copy. The copy was in the given part of the post. Now since I've learned there are at least five ways to copy the code, maybe I wasn't specific enough. It's just at the time, I didn't know there were five or more ways. I surely didn't expect to run into commands/methods that include "bookmark".

I don't expect that every form will need to be doing a copy record. But I've had enough that do in the past, that it's worth making the "hook" in the template form, at least for me. It's a command button in the footer that has a simple parameter to enable or not for any or all users of a particular form.

If you look at the actual copy code commands (Sub sFrmCopyRecord), you'll see that there's about six lines of code that do the work of the actual copying, if you exclude a DIM or two. And I can get rid of one of those if I always copy to the same table. So, is it really worth rewriting and all the testing to possibly save two lines of code? Besides, it would probably take four or more lines of code to work around the order of the three for the modifications I need to make to the newly copied record (since we would have to call and return to/from the helper form module.)
 

Users who are viewing this thread

Back
Top Bottom