Modifying report Fonts etc., in preceeding form

thudson

Old Programmer
Local time
Today, 21:08
Joined
Apr 29, 2011
Messages
68
I have a form that sets up all of the necessary content that is being passed to the report. But I also want to set the Font, Font size and Font color, before the report is produced. Also a requiement would be that the font list must be the installed fonts on the computer.

Does anybody have any information on how to do this?

I had a look at customizing the Ribbon, but once the Report is opened you can't alter the fonts.
 
you are making reports, waaaay too difficult.
It would be too much trouble when you can just build a report and print to it.
 
I'll give this to you in two parts.

First, the report can be opened in acDesignView, with the acHidden option, where you can then for that report, do a

Code:
For Each xCtl in rptobject.Controls
   SELECT CASE xCtl.ControlType
      CASE acTextBox, acComboBox, acListBox, acControl, acLabel
        xCtl.FontName={your favorite font name goes here, probably in quotes}
   END SELECT
Next xCtl

In essence, you step through the report and find those controls for which a font even makes sense. After that, you can either close the form with the close option acSaveYes and then re-open it in the acReportView or I think you can just open it again in another view without closing it from design view first - if you didn't want to keep the changes.

Now, the second part of this is to find out what to use for a font name. You might be able to take the easy way out because USUALLY, if the font exists in the appropriate folder, it is available under Windows. So you can do something with the file-system object (which you can look up online to see how to do this) where you search for all files in C:\Windows\Fonts\ - but remember that the definitive way to do this is more complex. You can also do a registry sweep (look this up online, and Access CAN do this...) so you find the font names.

For example, see article: https://msdn.microsoft.com/en-us/library/0yf5t4e8(v=vs.110).aspx
 
Ranman256
I am trying to do something unusual!
I am trying to emulate a web page I have that prints in the correct place a verse that can be used in a greetings card. I want the user to be able to choose the font, size and color.
The Doc Man
Thank you I will look into your suggestions!
 
Following the Doc Man's lead I made a subroutine to get you started. I believe the only control you are interested in is Text1 so this part is easy.


Code:
Public Sub ChangeFontName(strReportName, strFontName)

DoCmd.OpenReport strReportName, acViewDesign
Reports.Item(strReportName)![Text1].FontName = strFontName
DoCmd.Close acReport, strReportName, acSaveYes

End Sub

You would call this something like:

Code:
Private Sub TestChangeFontName()

ChangeFontName "Rep_Land_Grt", "Times"

End Sub

I tested it that way in a module and this works but the screen jumps around a bit when I run it. Maybe it will be ok from a form.

I'm researching/experimenting getting a list of valid font names. I'll let you know.
 
http://www.access-programmers.co.uk/forums/showthread.php?t=152738 has the best code I could find for getting the font names. Following the instructions in that thread, I put the code in a module named Enum Fonts, added a combo box to the Frm_Verses_mstr form and named it cboFonts. I gave it a default value of "Arial". I added the following to the form's open.

Code:
EnumFontToControl "Frm_Verses_mstr", "cboFonts"
I added this sub routine to the Frm_Verses_mstr module


Code:
Public Sub ChangeFontName(strReportName, strFontName)

DoCmd.OpenReport strReportName, acViewDesign
Reports.Item(strReportName)![Text1].FontName = strFontName
DoCmd.Close acReport, strReportName, acSaveYes

End Sub


And I changed Cmd_Open_Rep_Click as shown below.


Code:
Private Sub Cmd_Open_Rep_Click()

Dim SelectedVerseID As Long
SelectedVerseID = Nz(DLookup("VerseID", "Verses", "Tick_Box = True"))
If Me.Cbo_Card_Size.Column(6) = "Portrait" Then
    ChangeFontName "Rep_Port_Grt", Me.cboFonts
    DoCmd.OpenReport "Rep_Port_Grt", acViewPreview, , Me.Filter & " AND VerseID = " & SelectedVerseID
Else
    ChangeFontName "Rep_Land_Grt", Me.cboFonts
    DoCmd.OpenReport "Rep_Land_Grt", acViewPreview, , Me.Filter & " AND VerseID = " & SelectedVerseID
End If

End Sub

It seems to work fairly well. Hope this helps.
 

Attachments

Had a day away from the PC!
Will work on your ideas tomorrow.
You have been a star!
 
Hi Sneuberg

Just tried your mods.
Had to add PtrSafe as am running 64 bit PC, but when I try to close the form I get a type mismatch error!

Is this as a result of the PtrSafe change?
I vaguely rememeber something about changing the user32, but can't remember what to.

The error is on 'AddressOf EnumFontFamProc'.
 
Hi Sneuberg

Just tried your mods.
Had to add PtrSafe as am running 64 bit PC, but when I try to close the form I get a type mismatch error!

Is this as a result of the PtrSafe change?
I vaguely rememeber something about changing the user32, but can't remember what to.

The error is on 'AddressOf EnumFontFamProc'.

I think it must be as it work fine on my 32 bit Office. I have a 64 bit Office on another hard drive. As soon as I can, probably later today, I'll reboot and check this out.
 
Right I found what to do.
I added Ptr to all of the Long calls.
Works OK.

I want to also change the font size and color.
Can this be done using this technique?
If so not sure how to do it!
 
As you add these to your project I'd just keep on expanding the subroutine that does the work. Below I've added the font size to the subroutine. I guess you should give this a better name, maybe ChangeReportProperties.

Code:
Public Sub ChangeFontName(strReportName, strFontName, strFontSize)

DoCmd.OpenReport strReportName, acViewDesign
Reports.Item(strReportName)![Text1].FontName = strFontName
Reports.Item(strReportName)![Text1].FontSize = strFontSize
DoCmd.Close acReport, strReportName, acSaveYes

End Sub

I tested this with a size of 24 as shown below and it works.

Code:
Private Sub Cmd_Open_Rep_Click()

Dim SelectedVerseID As Long
SelectedVerseID = Nz(DLookup("VerseID", "Verses", "Tick_Box = True"))
If Me.Cbo_Card_Size.Column(6) = "Portrait" Then
    ChangeFontName "Rep_Port_Grt", Me.cboFonts, 24
    DoCmd.OpenReport "Rep_Port_Grt", acViewPreview, , Me.Filter & " AND VerseID = " & SelectedVerseID
Else
    ChangeFontName "Rep_Land_Grt", Me.cboFonts, 24
    DoCmd.OpenReport "Rep_Land_Grt", acViewPreview, , Me.Filter & " AND VerseID = " & SelectedVerseID
End If

End Sub

For the combo box I'd just put the values in it. There's not that many.
You know like 8;10;11;12; etc
 
Got a message 'Not enough Arguments'
Realised that the sub routine in Module 1 had 3 arguments, so just added the Font size argument on the end of the line:
ChangeFontName "Rep_Port_Grt", Me.CboFonts, Me.CboFontSz

Now want to set the Font color!
I'm sure I have seen some where that you can display the Office color chooser to select a color, but can't find where, then use this color to change the font color.
 
Attached you will find a database with a color picker and instructions on how it was installed. It not likely that this will work on your 64 bit Office system as it has a declaration in the Color Dialog module. Since you've already preformed the required ptrSafe modifications once before I've left that for you to fix.
 

Attachments

Suggest changing the first line in the ChangeFontName sub to

Code:
DoCmd.OpenReport strReportName, acViewDesign, , , acHidden

to keep it from flashing up during the changes.
 
just save the fonts name, size, color, attributes etc. to a table and when the report load just dlookup the report name from this table and return the attributes you want to set.
 
just save the fonts name, size, color, attributes etc. to a table and when the report load just dlookup the report name from this table and return the attributes you want to set.
I thought that too, but these attributes can't be set during the form load. The have to be changed in design view.
 
I'm not clear on step 3.
When you say right click on Frm_Verses_Mstr do you mean for the whole form i.e. click on dot in top left corner or do you mean on the textbox, if not there where do you click?
 
Oops, That should read

3. In the design view of Frm_Verses_mstr, right click on a command button named ChooseColor you just added, click Build Event, and choose Code Builder. Enter Me!txtForeColor = ChooseWebColor(Me!txtForeColor), i.e., make the code look like ...
 

Users who are viewing this thread

Back
Top Bottom