Font Dialog Box
-
Sunday, April 08, 2012 6:58 PM
In Access 2000, I want to make the Font dialog box available when a user clicks a button on a form. My intention is to let a user select a font and font size for use when printing address labels.
Can someone suggest Visual Basic code I can use to display the Font dialog box?
All Replies
-
Sunday, April 08, 2012 8:45 PMSee the reply by Geof in http://vbcity.com/forums/t/141908.aspx. You can download a sample database with - among many other things - code for a font dialog.
Regards, Hans Vogelaar
-
Sunday, April 08, 2012 10:49 PM
Thanks, Hans.
I tried to go to the web site you suggested, several times, but always got the response that the site is unavailable. I hiope that's just temporary.
-
Sunday, April 08, 2012 11:25 PM
Lebans also has a demo using the winAPI for this, see below thread:
http://www.lebans.com/fontcolordialog.htm
Hope this helps,
Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.- Proposed As Answer by Hans Vogelaar MVPMVP Sunday, April 08, 2012 11:34 PM
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Friday, April 20, 2012 3:09 AM
-
Sunday, April 08, 2012 11:33 PMI can't get to that page either now - try the one suggested by Daniel.
Regards, Hans Vogelaar
-
Monday, April 09, 2012 4:36 PM
I went to the web site Daniel recommended. From there, I downloaded the file ChooseFontColorDialog.zip. That contained over four pages of uncommented, complex code. It's going to take several hours for me to figure out what that code is doing.
Surely, there's a simpler way to use the Fint dialog box?
-
Monday, April 09, 2012 5:05 PM
The code is complicated, but you don't have to understand it.
Import the modFontPicker dialog into your database.
As an example, to let the user change the font of the text box txtAddress on a form, use
Call test_DialogFont(Me.txtAddress)
You can use this line in the On Click event of a command button, or in the On Dbl Click event of the text box, or whatever.
That's it!
Regards, Hans Vogelaar
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Friday, April 20, 2012 3:09 AM
-
Monday, April 09, 2012 7:57 PM
It would be great to understand it, but as Hans stated you don't have too perse.
Follow the instructions as Hans give you and you would be good to go.
Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.- Edited by danishani Monday, April 09, 2012 7:59 PM
-
Monday, April 09, 2012 10:38 PM
I disagree about not having to understand the code. As a matter of principle, I never incorporate code that I don't understand in an application that I'll release to users.
Some time in the future, a user is likely to come up with a problem or extra requirement that affects the code. If I don't understand the code: mud on my face!
-
Tuesday, April 10, 2012 3:55 AM
Good for you, if you want to understand the code, you need to dig into API and VBA.
You have to make some time for that.
Some API's are easy to figure out, this one is quite complex to figure out.
To give you some heads up, I give you some basic explanation below with the logic on how it's build up and what it does.
For more info on the ChooseFont WinAPI in combination with the Common Dialog WINAPI, see below threads:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645524(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646914(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646832(v=vs.85).aspx
The 1st part are Constants and Types being used as handlers and variables mainly for the Win API's.
Then the 2nd part are the declarations of the WinAPI's (ChooseFont, GlobalLock, GlobalAlloc, CopyMemory, GetDeviceCaps and GetDC). Note: They are 32-bit API's. When using 64-bit windows, you need to convert these to 64-bit. Info on this you can find in below thread:
http://www.jkp-ads.com/articles/apideclarations.asp
Then the 3rd part are help functions (MulDiv, ByteToString, StringToByte) to do some calculations and conversions of data.
The 4th part function DialogFont is basicly creating the Font Dialog window with info, calling the WinAPI's and help functions created in earlier stage.
The last part Function test_DialogFont is calling the function DialogFont and with that you can change the font settings with the Control you have used.
Hope this helps,
Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.- Edited by danishani Tuesday, April 10, 2012 6:08 AM typo
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Friday, April 20, 2012 3:10 AM
-
Tuesday, April 10, 2012 11:33 PM
Many thanks, Danishani, for all the help. I'll be looking at the sites you suggested. Thanks, especially for taking the time to provide an explanation of the Leblanc code.
Although I've been developing Access applications since the days of Access 2.0, I've so far been able to avoid referring to API functions. Now I'll bite the bullet, as they say, and work at getting my mind around how to work with API functions.
-
Wednesday, April 11, 2012 2:40 AM
You are welcome, and goodluck with learning the API functions! :)
Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered. -
Thursday, April 12, 2012 9:05 PM
I've sent several hours examining the Lebans code, and have learned a lot while doing so.
I did run into a couple of problems, but have been able to solve them.
When the text_DialogFont function first ran, the compiler did not like the statement:
ctl = .Name & " - Size: " & .Height
I changed that statement to:
ctl.ControlTipText = .Name & " - Size: " & .Height
That solved the problem. My guess is that might be what Lebans intended?
Also, when I changed the font color in the dialog box, the color change did not appear in the text.
I solved that problem by inserting the statement:
ctl.Forecolor = .color
Now all works fine.
Thanks to you all for your help.
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Friday, April 20, 2012 3:10 AM

