combining constants

P

pow67

[BusName], one field in my report, prints in a font which is bold,
larger size and colored if certain criteria are met. Otherwise [BusName]
prints using the default font.

My general declaration statement is:

Option Compare Database
Public Const BoldColor = vbBlue
Public Const BoldSize = 14
Public Const BoldWeight = True

Option Explicit

The code in my class module is:

If (Me![BOLD] Or Me![PLUS]) = True Then
Me![EXTRA].Visible = True
Me![BusName].ForeColor = BoldColor
Me![BusName].FontSize = BoldSize
Me![BusName].FontBold = BoldWeight
Else:
Me![EXTRA].Visible = False
Me![BusName].ForeColor = vbBlack
Me![BusName].FontSize = 10
Me![BusName].FontBold = False
End If

Is it possible to combine the attributes in the general declaration into
one constant such as BoldPrint and then in the class module I could use
something like:

If (Me![BOLD] Or Me![PLUS]) = True Then
Me![EXTRA].Visible = True
Me![BusName] = BoldPrint

Thanks in advance.

CW
 
S

Sandra Daigle

I don't think so - I believe you will have to continue specifying the
properties separately.
 
D

Dirk Goldgar

pow67 said:
[BusName], one field in my report, prints in a font which is bold,
larger size and colored if certain criteria are met. Otherwise [BusName]
prints using the default font.

My general declaration statement is:

Option Compare Database
Public Const BoldColor = vbBlue
Public Const BoldSize = 14
Public Const BoldWeight = True

Option Explicit

The code in my class module is:

If (Me![BOLD] Or Me![PLUS]) = True Then
Me![EXTRA].Visible = True
Me![BusName].ForeColor = BoldColor
Me![BusName].FontSize = BoldSize
Me![BusName].FontBold = BoldWeight
Else:
Me![EXTRA].Visible = False
Me![BusName].ForeColor = vbBlack
Me![BusName].FontSize = 10
Me![BusName].FontBold = False
End If

Is it possible to combine the attributes in the general declaration into
one constant such as BoldPrint and then in the class module I could use
something like:

If (Me![BOLD] Or Me![PLUS]) = True Then
Me![EXTRA].Visible = True
Me![BusName] = BoldPrint

Thanks in advance.

CW

No, I'm afraid not. You could of course create your own scheme for encoding
multiple attributes in one constant, and then have a routine that extracts
those attributes and applies them. For (simple) example:

'----- start of example code -----

'print constants: ForeColor;FontSize;FontBold
Public Const NormalPrint = vbBlack & ";10;0"
Public Const BoldPrint = vbBlue & ";14;-1"


Sub SetPrintProperties(ctl As Control, PropString As String)

Dim aProps() As String

aProps = Split(PropString, ";")

With ctl
.ForeColor = CLng(aProps(0))
.FontSize = CInt(aProps(1))
.FontBold = CBool(aProps(2))
End With

End Sub

' ... somewhere else ...
If (Me![BOLD] Or Me![PLUS]) = True Then
Me![EXTRA].Visible = True
SetPrintProperties Me![BusName], BoldPrint
Else
SetPrintProperties Me![BusName], NormalPrint
End If

'----- end of example code -----

This wouldn't seem worth it to me unless you were going to use these same
settings repeatedly.
 

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