Continuing the Introduction to VBAccess:
In this example I did the click event two ways. Both work! It is interesting that when you use the text property on txtShowName you have to set the focus prior to the assignment, but when you do not use the text property you do not have to set the focus.
In the next example, I am going to start the form by linking it to the Drive table in the Donor database. I than brought in several fields including the drive number, the drive name, the goal and the YTD for the year. I then added a field called txtDiff that I am going to use in a calculation to tell the difference between the goal and the YTD total.
Note that in the properties I set all of the numeric fields to currency. I then created two buttons to do the calculation in two different ways.
On the first button which is labeled Find Difference, I simply calculated txtDiff by subtracting txtYTDTotal from txtGoal (note that in propeties these are the names I gave the fields - I changed the original names which did not have txt in front of them). In doing the calculation, I used Val which does a conversion to numeric data prior to doing the subtraction. I stored the answer in txtDiff. On the next example, I established a variable called wkDiff using the DIM statement and making it size double. I then did the calculation and stored the answer in wkDiff. When the calculation was done, I assigned what was in my work variable to the field on the form txtDiff. Both ways work fine. One is putting the answer directly on the form, the other is putting the calculation in a work area and than transferring it to the form.