Need a quick lesson

B

Bill Stanton

My intuitive sense tells me that the functional portion of the
segment of code, headed by the "block comments" below,
can be greately simplyfied and reduced.
Maybe something like: (I don't know how to declare the
data type for SelMedia so that it can be used to make reference
to the form's label controls whose name is passed to MediaSelect?)

Public Function MediaSelect(SelMedia As String)
Call SetMediaFocus(SelMedia, 14, 700) 'Highlight selection
Call SetMediaFocus(CurMedia, 11, 400) 'Remove highlighting from old
selection
CurMedia = SelMedia 'Make selection
End Function
Private Sub SetMediaFocus(SelCntl As ?????, PtSize As Integer, Weight As
Integer)
Me.SelCntl.FontSize = PtSize
Me.SelCntl.FontWeight = Weight
End Sub


Public Function MediaSelect(SelMedia As String)
'=====================================================
' The user is required to identify the media associated with the volume
before
' answering the question as to whether the volume is new or existing. The
eight
' media options displayed at opening are set to a point size of 11 and
weight of
' "Normal", i.e., 400. This function is invoked by clicking upon one of the
label
' boxes whose "On Click" event contains the invocation expression that
identifies
' the media, e.g., the label control for "Cassette" is named "SelCA". Thus,
we
' effectively give the functionality focus to whatever media is detected and
signify
' that by setting its point-size and weight to 14/Bold and revert the
previously
' selected media to its nominal settings. In other words we highlight to
show focus.
'=====================================================

Select Case SelMedia 'Set selected option point size to 14 and font weight
to "Bold".
Case "SelCA"
Me.SelCAS.FontSize = 14
Me.SelCAS.FontWeight = 700
Case "SelCD"
Me.SelCD.FontSize = 14
Me.SelCD.FontWeight = 700
Case "SelCD2pl"
Me.SelCD2pl.FontSize = 14
Me.SelCD2pl.FontWeight = 700
Case "SelDVD"
Me.SelDVD.FontSize = 14
Me.SelDVD.FontWeight = 700
Case "SelRR7"
Me.SelRR7.FontSize = 14
Me.SelRR7.FontWeight = 700
Case "SelRR10"
Me.SelRR10.FontSize = 14
Me.SelRR10.FontWeight = 700
Case "SelVy10"
Me.SelVy10.FontSize = 14
Me.SelVy10.FontWeight = 700
Case "SelVy12"
Me.SelVy12.FontSize = 14
Me.SelVy12.FontWeight = 700
End Select

Select Case CurMedia 'Set previously selected media to its nominal display
properties.
Case "SelCA"
Me.SelCAS.FontSize = 11
Me.SelCAS.FontWeight = 400
Case "SelCD"
Me.SelCD.FontSize = 11
Me.SelCD.FontWeight = 400
Case "SelCD2pl"
Me.SelCD2pl.FontSize = 11
Me.SelCD2pl.FontWeight = 400
Case "SelDVD"
Me.SelDVD.FontSize = 11
Me.SelDVD.FontWeight = 400
Case "SelRR7"
Me.SelRR7.FontSize = 11
Me.SelRR7.FontWeight = 400
Case "SelRR10"
Me.SelRR10.FontSize = 11
Me.SelRR10.FontWeight = 400
Case "SelVy10"
Me.SelVy10.FontSize = 11
Me.SelVy10.FontWeight = 400
Case "SelVy12"
Me.SelVy12.FontSize = 11
Me.SelVy12.FontWeight = 400
End Select

CurMedia = SelMedia


End Function
 
A

Albert D. Kallal

Yes, you sure can.

You can use any collection object with a string.

So, in place of

forms!Customer!LastName

You can use

forms("Customer")!LastName

Or, even

forms("customer")("LastName")

Of course the string "customer" can also be a variable of your choice.

So, in your case, you are reference the fields collection.



So, you select case code of:
Select Case SelMedia 'Set selected option point size to 14 and font weight
to "Bold".
Case "SelCA"
Me.SelCAS.FontSize = 14
Me.SelCAS.FontWeight = 700

Can be changed to:


me(SelMedia).FontSize = 14
me(SelMedia).FontWeight = 700

So, you dump the whole select case, and simply use the string value that you
pass. In looking at the above code, it does seem that you pass SelCA but the
actual control name on the form seems to be SelCAS (with he letter s). So,
either modify your code to pass the correct control name, or simply go:

dim tSelMedia as string

tSelMedia = SelMidea
if tSelMedia = "SelCa" then
tSelMedia = tSelMedia & "S"
end if

Anyway, I think you get/see the idea I am getting at in the above. In fact,
since you only have ONE exception to adding the letter "s", you might just
change the calling code (anyway,....I sure you got enough here to run with
this on your own!).


You can also do the same with SetMediaFocus. So, just pass a sting. you get:

Private Sub SetMediaFocus(strCntl As string, _
PtSize As Integer,_
Weight As Integer)

Me(strCntl).FontSize = PtSize
Me(strCntl).FontWeight = Weight

End Sub


Like I say, ALL collections in ms-access work this way, so you can use a
string for forms, controls or even your own custom collections.

Good Luck!
 
B

Bill Stanton

Thanks Albert, I'm done for the night. I'll assimilate
all of what you've taught me here, make the changes
tomorrow and post back the results.
Thanks again,
Bill
Graeagle, California
 
B

Bill Stanton

A most valuable lesson Albert. If the Access HELP
text has an explanation of the use of the collection
objects using the syntax you've described for me,
I sure missed it.

I went back in the current project and cleaned up
whatever code failed to make use of what I've just
learned from you.

Thanks again, and a Merry Christmas and Happy
New Year to you.
Bill Stanton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top