473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Writing Solid VBA

171 100+
Hi Everyone,

I Currently have two problems:
Problem 1: My Access DB has gotten to a stage where everything works, but there are many things which don't need to be there, and despite my best efforts not to, In all the exitement of coding I have written a fair bit of code which I do not understand. So my question is, are there books (etc) that I can refer to for learning to write code, where when reading the code, I or any one else who understands VBA can comprehend what is going on very easily.

Problem 2: My Access DB is running slowly I have many reports which take ages to load due to their complex underlying Queries. The slowness could be because my backend is only Access and not SQL server (etc). But I suspect that there would be a way to write better (more efficient) SQL Strings which will run faster. I currently use the query builder to build my queries. But I would be able to write them into the VBA if that makes it more efficient. I know this is a very general question, but any guidance would be appreciated even if is a good book in the subject.


Much Thanks in advance.
Jul 25 '08 #1
6 1863
PianoMan64
374 Expert 256MB
To answer your 2 questions,

Question 1. The easiest way that I've found to write code, is to Comment, comment, comment. Everything that you write, put at the top of the routine what it does, and what the general purpose is for that Function, Subroutine, or Property. Show how it is used. As for lines within the code. Comment what it means and what it is doing. This will make is easy for you and also for anyone else that may come after you to begin coding where you left off.

As for any resources for learning how to code VBA, I would recommend any microsoft publishing book on VBA or any book that deals with the level of VBA programming that you understand. The other type of book that you may want to look into is a MS Access Programming Book. These are loaded with VBA code that is specificly for MS Access Only. If this is the area that you want to concentrate your efforts, that is always a good choice.

Question 2:

Since your queries can sometimes be slow due to either design, or lack of structure (i.e. no indexes on key fields that are linked between tables) this will slow the query down 10 to 1000 times depending on the number of records involved. I would recommend, that if you're planning on expanding the data in the database tables, that it may be time to Upzise to either MS SQL Express (FREE) or Oracle 10g Express (Free) or if you want to spend a little bit of money MS SQL Developer ($49.95+shipping) from microsoft. The only limit is 4Gig database size. If you're wanting something larger than that, then you're going to have to upgrade, and I don't know if that is what your database is going to need or not. Just giving you some options.

If you do want to see if your queries that you've written are good queries, you're more than welcome to post them on here and ask if anyone of the experts can take a look at them.

I hope all this helps some,

If you have any more questions, feel free to post again.

Thanks,

Joe P.
Jul 25 '08 #2
iheartvba
171 100+
To answer your 2 questions,

Question 1. The easiest way that I've found to write code, is to Comment, comment, comment. Everything that you write, put at the top of the routine what it does, and what the general purpose is for that Function, Subroutine, or Property. Show how it is used. As for lines within the code. Comment what it means and what it is doing. This will make is easy for you and also for anyone else that may come after you to begin coding where you left off.

As for any resources for learning how to code VBA, I would recommend any microsoft publishing book on VBA or any book that deals with the level of VBA programming that you understand. The other type of book that you may want to look into is a MS Access Programming Book. These are loaded with VBA code that is specificly for MS Access Only. If this is the area that you want to concentrate your efforts, that is always a good choice.

Question 2:

Since your queries can sometimes be slow due to either design, or lack of structure (i.e. no indexes on key fields that are linked between tables) this will slow the query down 10 to 1000 times depending on the number of records involved. I would recommend, that if you're planning on expanding the data in the database tables, that it may be time to Upzise to either MS SQL Express (FREE) or Oracle 10g Express (Free) or if you want to spend a little bit of money MS SQL Developer ($49.95+shipping) from microsoft. The only limit is 4Gig database size. If you're wanting something larger than that, then you're going to have to upgrade, and I don't know if that is what your database is going to need or not. Just giving you some options.

If you do want to see if your queries that you've written are good queries, you're more than welcome to post them on here and ask if anyone of the experts can take a look at them.

I hope all this helps some,

If you have any more questions, feel free to post again.

Thanks,

Joe P.

Thanks alot Joe, I have only a slight idea of the purpose of indexes as well as how to use them effectively I will do some more research on them.
Jul 26 '08 #3
youmike
69
I endorse what JoeP says about comments and would add some other thoughts, but recognise that your question is a huge one.

1. Get to know a naming convention and use it rigidly for all the objects in your code. The Leszynski convention would be my recommendation. There are plenty of online references to it.

2. Get into the habit of indenting your code when you use Do Loops, If Clauses and the like. This makes it so much easier to follow the logic when fiixing is needed.

3. When you analyze what you need your code to do, try to break the task into self contained sub tasks which can be called as needed, with the necessdary parameters being passed at the start and end. Put the code in clearly named modules, which can be called from objects in the various forms, reports and so on .My own preference is to take this modular approach to the point that all necessary SQL is declared as a string constant embedded in the module that holds the procedure that needs it.

4. Personally, I favour an approach which uses multiple front ends linked to a common back end, with each front end concentrating on a clearly defined need, and I tend to separate needs to summarise and report from the need to process information. This is another big topic.

5. Stay away from macros!
Jul 26 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi. Just to add to what JoeP and YouMike have already advised, ensure that you define the relationships between all tables at the design stage (i.e. setting appropriate primary keys and then setting explicit 1-many relationships between tables). Indexes for primary keys are created automatically, and where relationships are already defined this helps the Access database engine with optimising query performance.

In queries, the use of IIF statements, DLookups and so on can have a drastic effect on performance. Eliminate these in large queries if at all possible (IIFs can always be replaced by custom-written VBA functions, which run around twice as fast). DLookup, DSUM and similar domain functions are excellent solutions where one-off lookups are needed, but because these functions effectively open and close a recordset every time they are called they can really slow down a larger query.

-Stewart
Jul 27 '08 #5
youmike
69
What Stewart added is arguably the most important point. In any DB application, the difference between good and poor performance is very often relationship definition. As an application designer, you have to train yourself to think quite differently about interaction between the data elements in the system you are designing. You'll find lots of help on the internet. Personally, I have gone back and back to the original IBM report by Dr E F Cobb and I have notes written by Paul Litwin which I've found useful over the years. Microsoft also have papers in their knowledge base and the early versions of Access (Version 2, Access 95 & 97) had very useful Manuals which are still relevant.

Finally, recognise that you never stop learning. I've been at it since IBM sold the first PCs and have over the years taught others, both formally in classes and informally on the job. I still treasure forums like this because they are such a great source of knowledge.

I could make available a list of books I've used over the years, if it would be of any help.
Jul 28 '08 #6
LosLobo
15
What Stewart added is arguably the most important point. In any DB application, the difference between good and poor performance is very often relationship definition. As an application designer, you have to train yourself to think quite differently about interaction between the data elements in the system you are designing. You'll find lots of help on the internet. Personally, I have gone back and back to the original IBM report by Dr E F Cobb and I have notes written by Paul Litwin which I've found useful over the years. Microsoft also have papers in their knowledge base and the early versions of Access (Version 2, Access 95 & 97) had very useful Manuals which are still relevant.

Finally, recognise that you never stop learning. I've been at it since IBM sold the first PCs and have over the years taught others, both formally in classes and informally on the job. I still treasure forums like this because they are such a great source of knowledge.

I could make available a list of books I've used over the years, if it would be of any help.
I would be interested in seeing any list of books you, Stewart or anyone else would like to recommend. Though this isn't my thread, I too am always looking to learn more and there is always something new I didn't know before. :-)
Jul 28 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

40
by: post400 | last post by:
Hi, there is another famous book 'Writing solid code' but does it apply to Python ? Or it's usable only by Microsoft C programmers ? The author seems to be an ex-Microsoft guy ! Thanks ,...
4
by: flupke | last post by:
Hi, at work we use a solid database and i need to develop an application that accesses it. Problem is the drivers: i only have some dll's lying around and jar. On winsdows i could get by by...
6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
9
by: 100 | last post by:
Has anybody read Steve Maguire's book "Writing solid code"? Do you think that the ideas in this book are not applicable in c# language? Does anybody find if(2 == i) istead of if(i == 2) as...
1
by: tradmusic.com | last post by:
Hi, Is it possible to set a border to only be on the right, bottom and left? I tried this, but it isn't working: border: 0px 1px 1px 1px solid #000000; Any help would be greatly...
7
by: John Pote | last post by:
Hello, help/advice appreciated. Background: I am writing some web scripts in python to receive small amounts of data from remote sensors and store the data in a file. 50 to 100 bytes every 5 or...
4
by: slahiri | last post by:
I am writing an I/O utility in C that accepts requests over a socket connection and persists the data that can be read by other processes. There could be data coming from hundreds of client...
15
by: Tommy B | last post by:
I was wondering if there was a way to take a txt file and, while keeping most of it, replace only one line. See, I'd have a file like: Tommy 555 Bob 62 Joe 529 And I'd want to set it to be:...
3
by: planetthoughtful | last post by:
Hi All, I'm building a Windows Form application that will use a Microsoft Access mdb file as a data store. I have a section of code that is executed when the main form is closed that _should_...
4
by: Jim | last post by:
Hi There, I'm trying to read a file character by character. When I write the file out, there is one extra character which shows on the screen as a solid circle with a small question mark in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.