Reuse code? (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 19:14
Joined
Sep 21, 2011
Messages
14,046
Hi everyone,

I am slowly realising that a piece of code that I wrote for one database could be used in another. One example is an email subroutine, in which I pass the email addresses, file to attach (if required), subject and body text.

Nothing fancy, but I can see that I could use this routine in a small database I am attempting for employee information.

What is the best way to be able to reuse this code?
What would happen if I perhaps 'enhanced' it with the option of multiple filenames split by ';' perhaps?, how would I get that amendment into wherever it was being used.?

TIA
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:14
Joined
Jul 9, 2003
Messages
16,244
I think some people use a library database but personally I don't agree with separating out the parts of my database so I don't do it that way.

MS Access has a very useful file insert option you can see a demo of it being used here:-

The time index link to the YouTube Video didn't work properly, so try this; choose Text Insert (1) on this page:-

https://sites.google.com/site/msaccess457966vmfjg/hints-and-tips/video-hints

Basically all it does is give you access to a folder and within that folder you can have sub folders, in these folders you can have textiles.

Just click on the text file and it pastes it straight into your code window for you.

It's very useful because it is available from any of your databases.

But it's even More useful than that! You might not realise it straight away but when you press the file open command and select a folder or file you don't need to just copy the file into your database, you can actually open the file and edit it so if you come up with improvements to your code you can quickly and easily amend your file.

I've been meaning to do a set of videos about it but haven't got around to it yet! It's not that it's difficult, anyone with competency in using a filesystem will "get it" immediately, however it's just not in your face obvious.



Sent from my SM-G925F using Tapatalk
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:14
Joined
Jul 9, 2003
Messages
16,244
The other thing I do is I have a Google website, a bit like the one linked to above, but it's private to me. I keep all my code snippets and copies of other peoples code, code I find useful and worry that it may disappear from the web.

A Google website is brilliant for this because it is searchable and you can add video, text, links. You can save files to it DB files PDF files zip files.

The only worry I had was that if anything went wrong I could lose the information in the website but I have found a way of saving a website to my local drive very easy with a nice free piece of software.

Sent from my SM-G925F using Tapatalk
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 19:14
Joined
Sep 21, 2011
Messages
14,046
Thank you Uncle Gizmo,
Could you please tell me what you use for saving the website. That might be something I could use also.
At present I am just feeling my way, but can see plenty of ways I could improve.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:14
Joined
Jul 9, 2003
Messages
16,244
Also, if I ever get another contract with the NHS, or a corporate I can put it on a CD to circumvent restricted Internet access policy...

Sent from my SM-G925F using Tapatalk
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:14
Joined
Sep 21, 2011
Messages
14,046
Not in Lloyds you wouldn't, they had locked down the DVD drive and I seem to recall USB sticks as well.
I worked for the NHS once and they could not get me the laptop in time, so I offered to bring in my own.
'You won't be able to connect it to our network' was the response
'No problem' was my reply, but I can set up the mailmerges on my laptop.

So I flitted to and fro with a memory stick copying files. :)

I wear a USB dog tag with any medical problems on it, given by the Bikesafe course, when out on my motorbike. If I ever came off, I doubt the ambulance crew would be allowed these days to plug it in to see my medical history. I still wear it though. :)
 

tranchemontaigne

Registered User.
Local time
Today, 12:14
Joined
Aug 12, 2008
Messages
203
Not having seen the videos, I can tell you that I often make standard code modules with useful functions, such as exporting recordset contents to MS Excel, logging run-time errors, performing file I/O operations, making Windows API calls, etc and importing copies of these modules into new MS Access files when needed. Having copies of these modules embedded within the MS Access "bundle" means that the database will remain operating as expected without risk of unintended impacts should future changes be made to the master modules.
 

speakers_86

Registered User.
Local time
Today, 15:14
Joined
May 17, 2007
Messages
1,919
I mostly have two modules, one called 's' and one called 'g'. The s is for specific, and only contains code that is just for that database. The g is for generic, and can be safely used in all of my databases. I also have a module called 'backend' which contains all of the functions I could perform to/with the backend from the front end, this is also generic. This is similar to using a library, by I try very hard to avoid references, so I just import them and risk versioning issues.
 

Users who are viewing this thread

Top Bottom