473,387 Members | 3,781 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,387 software developers and data experts.

VBA Tutorial

158 100+
Does anyone have any insight about what would be some of the best literature on the web today on how to construct syntax in VBA from the start?

What I am looking for is "learn how to tie your shoes" basic literature. The most basic of the basic of the basic.

Most of what I am getting from anywhere is "how to use functions" and how to write them in VBA.

Here is an example:
Expand|Select|Wrap|Line Numbers
  1.   Option Compare Database
  2.  
  3.  
  4. Sub Form_current()
  5. Dim strParentDocName As String
  6.  
  7. On Error Resume Next
  8. strParentDocName = Me.Parent.Name
  9.  
  10. If Err <> 0 Then
  11. GoTo Form_current_exit
  12.  
  13. Else
  14. On Error GoTo Form_Current_err
  15. If Me.Parent.Name = "Work_Order_Details_SubForm" Then
  16. Me.Parent![Tasks_Form].Requery
  17. End If
  18. End If
  19.  
  20. Form_current_exit:
  21. Exit Sub
  22.  
  23. Form_Current_err:
  24. MsgBox Err.Description
  25. Resume Form_current_exit
  26.  
  27. End Sub 
This doesn't teach me anything. I may have a working function but I have no clue why it work or understand the reasons why I must quote " " around Work_Order_Detail_Subform
Expand|Select|Wrap|Line Numbers
  1.  If Me.Parent.Name = "Work_Order_Details_SubForm" 
because sometime you don't need to and other time you have to put that line in [ ] but if it is on a page then I must first put Form! but other time maybe not because of a reason or another..... For me this is like a 50 years + of experience contractor would get started at showing a 5 year old on how to build a house without showing the kid why he should use a saw and not a shovel to cut wood to start with.

I really don't want to learn what different function do and where they can be used, I want to learn why I would use a function instead of another and why do I have to bracket some in a syntax and why sometime I must put them in "" instead.

AH! Eureka - I am looking for the "CONVENTION" on how to write VBA

Forgive me English is not my first language, I probably do not make much sense to a lot of people.
Oct 31 '09 #1

✓ answered by MMcCarthy

You will find a couple of articles in our Insights section which may help. Here are a couple to get you started.

VBA Event Driven Programming

Access Built in Functions

Macro's or VBA

Also if you have any experience with macros you can create some macros and then convert them to VBA. This will allow you to see how the code translates.

If you have any specific questions please feel free to ask them. That's why we're here.

Mary

7 3401
Guido Geurs
767 Expert 512MB
dear,

search on the web for " free ebook pdf vba dummy".
I have found several sites where you can download these books for free !!


br,
Nov 4 '09 #2
Dököll
2,364 Expert 2GB
You actually came to the right place, do stay tuned... also good job posting an example. Do tell us what you are after, what you hope to achieve with much effort, and we'll try to steer you in the right direction.

I would also search the VBA forum intensively, just to see what's there.

L8ter!
Nov 5 '09 #3
MMcCarthy
14,534 Expert Mod 8TB
You will find a couple of articles in our Insights section which may help. Here are a couple to get you started.

VBA Event Driven Programming

Access Built in Functions

Macro's or VBA

Also if you have any experience with macros you can create some macros and then convert them to VBA. This will allow you to see how the code translates.

If you have any specific questions please feel free to ask them. That's why we're here.

Mary
Nov 5 '09 #4
MMcCarthy
14,534 Expert Mod 8TB
To get you started with some basic conventions in VBA.

All strings (Lines of text) have to be surrounded by double quotes. However, you should note that any substrings have single quotes. By this I mean if you had a query like:

SELECT CustomerName FROM Customers WHERE City= "New York"

and you had to put that in a string in VBA to pass it to a function then you would have to write it as follows:

"SELECT CustomerName FROM Customers WHERE City= 'New York' "

I hope this makes sense.

Another convention you should be aware of is the fact that all dates must be surrounded by hash marks as follows:

#04/09/2009#

Mary
Nov 5 '09 #5
NeoPa
32,556 Expert Mod 16PB
Someone posted Microsoft Access Tutorial recently. I haven't been through it in detail, but I had a quick look and it seemed pretty good. I decided to save it for re-use whenever anyone (like yourself) asked for something like this.

A couple of links that clarify what Mary was talking about (Quotes (') and Double-Quotes (") - Where and When to use them & Literal DateTimes and Their Delimiters (#)). Technically (not necessary, but is good practice if you ever want to move on to other RDBMSs) any string literal used by SQL should be enclosed in single-quotes (').

Good luck with your learning.
Nov 6 '09 #6
Delerna
1,134 Expert 1GB
And just to answer the two specific questions that I see in your post.

Expand|Select|Wrap|Line Numbers
  1.  If Me.Parent.Name = "Work_Order_Details_SubForm"  
  2.  
here you are comparing the content of an objects property (Me.Parent.Name) against a string value, to control whether a piece of code should get executed or not.

The object is (Me.Parent) and the property is (Name).
The name property is a string therefore what you are comparing it with
must also be a string.

Speaking in the context of your question
In VBA, text enclosed within "" is a string
Text not enclosed within "" is a variable

So your code can also be written like this

Expand|Select|Wrap|Line Numbers
  1.  Dim Work_Order_Details_SubForm as string
  2.  Work_Order_Details_SubForm ="Work_Order_Details_SubForm"
  3.  If Me.Parent.Name =   Work_Order_Details_SubForm THEN
  4.  
Here Work_Order_Details_SubForm is a variable for storing strings.

Notice there is no "". It is comparing the content of one object against the content of another object, whereas your code is comparing the content of an object directly against an actual string and therefore needs the "" for the VBA interpretor to recognise it as such.

Without the "" the VBA interpretor would think it was a variable
Nov 8 '09 #7
Delerna
1,134 Expert 1GB
Now for the square brackets.
This one is a bit more difficult as there are variations to the rule.

It is generally used in conjuction with the name of an object.
For example, the name of a field in an sql query
Expand|Select|Wrap|Line Numbers
  1.    SELECT FieldName FROM TheTable
  2.  
Notice there are no square brackets around anything.
If however my personal naming convention separated words with spaces instead of capitalized first characters.


Expand|Select|Wrap|Line Numbers
  1.    SELECT Field Name FROM The Table
  2.  
This would not work because Field and Name would be considered as two fields and there is no comma between them. The query would also look for a table called The.

Table would be considered as erroneous....incomprehensible nonsense.
You must write the query then, like this
Expand|Select|Wrap|Line Numbers
  1.    SELECT [Field Name] FROM [The Table]
  2.  
The square brackets forces the two words, Field Name, to be read as one field.
Get it?
As mentioned, there are variations to the use of [] but they all exist for similar reasons.

Incidentally, this
Expand|Select|Wrap|Line Numbers
  1.    SELECT [FieldName] FROM [TheTable]
  2.  
is not wrong, just unnecessary to include the [] here and therefore, that is the reason they are sometimes there and sometimes not.



I hope that helps a little. Spelling all this out in a tutorial can make for incredibly boring reading and in reality is probably better gained through experience and asking (specific) questions. It is a long road but the journey is very satisfying even if sometimes frustrating.
At least... it is for me.


EDIT
My anti tutorial comment is directed more towards things like
when to use [] and when not to.
It is not intended as a slurr against "VBA Basics" tutorials
Nov 8 '09 #8

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

Similar topics

1
by: Rhino | last post by:
Can anyone point me to a good free XSLT Tutorial online? I looked for some a few months ago and didn't find anything very good. I'm hoping some of the experts here can point me to a good XSLT...
15
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
18
by: Xah Lee | last post by:
i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html Here are some quick critique: quick example: If the input string is too long, they don't truncate it,...
0
by: Joe Mayo | last post by:
I've recently updated the C# Tutorial at C# Station with a new addition, Lesson 17: Enums. The C# Tutorial may be found at http://www.csharp-station.com/Tutorial.aspx. Other updates include:...
10
by: Safalra | last post by:
When a poster in a forum I frequent said they were beginning to learn HTML, I thought I should direct them to a good HTML tutorial so that they wouldn't start using <blink> and the like....
11
by: Magnus Lycka | last post by:
While the official Python Tutorial has served its purpose well, keeping it up to date is hardly anyones top priority, and there are others who passionately create really good Python tutorials on...
7
by: Turbo | last post by:
I have a written a detailed html tutorial here:- http://sandy007smarty.seo.iitm.ac.in/2006/09/26/html-tutorial/ I know there are a couple of html tutorials out there. But its a tutorial without...
2
by: sara | last post by:
Hi All, I learned C++ long time ago and now I want to review all of its details in a short time like a week. I wonder if there is a good tutorial you know which I can read for this purpose....
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.