Dim is a reserved word to reserve space for a variable in memory. You should set your database default for Option Explicit, which forces you to declare variables before you run a function, etc.
The syntax is:
Dim stVariable As ...
Where Dim is the declaration, stVariable is your variable name (usually with a prefix (st) that refers to the Type of variable you are declaring. In this case "As String".
When you declare a variable, space is reserved for the variable in memory and when the variable is used, Access VBA uses a short cut to the memory register, rather than creating the memory register on the fly in the middle of your code.
The Type of variable you declare determines what can be stored in the memory space, and how much memory is reserved for the variable.
You need to read up on this in one of the fine Wrox books on VBA.
Me! refers to the form or report running the particular sub or function you are in. So if you have a variable on a form you want to capture, like the value in a text box, you would declare the variable, and then grab the value from the text box like this:
Dim stValue As String
stValue = Me!txtMyTextBox
You can also refer to the form like this, instead of using Me!
stValue = Forms!frmMyForm!txtMyTextBox
That is the long way around that you would have to use in a function that you might be running from a module.
HTH
mmcdonal
|