Hi John,
I also sometimes use poor names when trying something out. But not to
any great extent.
There are some other ways to do the thing. The one you yourself
suggested, as modified by me. Marshall's. Or even a hybrid. It mostly
depends on how you want to specify the varying fields. There is the
specification within the call to the function or the specification, for the
most part, within the function. Here is an example of the latter that could
be used if your field sets are sequentially numbered (as your original code
implies):
Private Sub IM1_Click()
FieldCalculate 1
End Sub
Private Sub FieldCalculate (intSet As Integer)
Select Case [longLVL]
Case 1 To 4
If Controls("longM" & intSet) < 0 Then
Controls("longM" & intSet) = Controls("longM" & intSet) + 75
If Controls("longPRA" & intSet) = 0 Then
Controls("longPRA" & intSet) = 236
Controls("dblPRP" & intSet) = Controls("longPRC" &
intSet) / _
Controls("longPRA" & intSet)
End If
End If
End Select
End Sub
You will notice that I am using the Controls collection of the form.
When Marshall used Me("xxxx"), there was an implied .Controls there because
the Controls collection is the default property of a form. Me of course
refers to the object the code is in. In this case a form. In my code the
Me. is implied. There is also an Item property of the Controls collection,
which again is the default property of the Controls collection. To access an
item in a collection, you can specify either an index number or the actual
name. Also, for a TextBox, there is a default property, which is Value. So
in fully qualified/explicit form it might look like:
Me.Controls.Item("longM1").Value
Most (all?) of this is in the help. However, as you stated, finding it
is problematic. I will say that after the fiasco with Access 2000's and I
think 2002's help, they improved with 2003 and again with 2007. After
initial training, a lot of this I have picked up over time by chance
encounter when trying to do something. So, if working with a form, I may
have been looking at the help for the form and noticed that the Controls
object was the default object. Just don't ask me to where find that
particular piece of information
. And of course becoming involved in the
Access discussion groups has expanded my knowledge. I am sure there are
books and web sites that give the details in different formats and ways.
Hope this is helpful to you,
Clifford Bass
John F said:
Which would make all of the fields involvd:
longLVL standard format
longM1 standard format
longPRA1 standard format
longPRC1 standard format
dblPRP1 format percentage
I am aware of the meaningful nameing convention and I use it grudgingly in
the final product. This however is a proof of concept and didn't try for good
form but rather proofing the functionality which means at the end I use the
heck out of the search and replace functionality.